This documentation is for WSO2 API Manager 1.10.0 View documentation for the latest release.
Page Comparison - Change the Default Mediation Flow of API Requests (v.7 vs v.8) - API Manager 1.10.0 - WSO2 Documentation

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Log in to the API Publisher.

  2. Click Add to create an API with the following information and then click Implement.

    Field
     

    Sample value
    Name
     

    YahooWeather
    Context
     

    /weather
    Version
     

    1.0
    ResourcesURL patterncurrent/{country}/{zipcode}
     

    Request types

    GET method to return the current weather conditions of a zip code that belongs to a particular country

  3. The Implement tab opens. Select Managed API, provide the information given in the table below and click Manage.

    FieldSample value
    Endpoint typeHTTP endpoint
    Production endpoint

    You can find the Yahoo weather API's endpoint from https://developer.yahoo.com/weather/. Copy the part before the '?' sign to get this URL: https://query.yahooapis.com/v1/public/yql

    To verify the URL, click the Test button next to it.

    Sandbox endpointhttps://query.yahooapis.com/v1/public/yql To verify the URL, click the Test button next to it.

  4. Click Manage to go to the Manage tab, provide the following information and click Save & Publish once you are done.

    FieldSample value
    Tier AvailabilityGold
    Keep the default values for the other attributes
     

  5. Download WSO2 Developer Studio (version 3.8.0 is used here) from http://wso2.com/products/developer-studio/ and open it by double clicking the Eclipse.app file inside the downloaded folder. 

  6. Click Window > Open Perspective > Other to open the Eclipse perspective selection window. Alternatively, click the Open Perspective icon shown below at the top right corner.
  7. On the dialog box that appears, click WSO2 APIManager and click OK.
  8. On the APIM perspective, click the Login icon as shown below.
     
  9. On the dialog box that appears, enter the URL, username and password of the Publisher server.
  10. On the tree view that appears, expand the folder structure of the existing API.
  11. Right-click on the in sequence folder and click Create to create a new in sequence.

    This is because you want the custom sequence to be invoked in the In direction or the request path. If you want it to be involved in the Out or Fault paths, select the respective folder under customsequences.

  12. Name the sequence YahooWeatherSequence.
  13. Your sequence now appears on the Developer Studio console. From under the Mediators section, drag and drop a Property mediator to your sequence and give the following values to the property mediator.

    Property NameNew Property
    New Property NameYQL
    Value TypeExpression
    Value Expression

    For the XPath expression, we take a part of the query in the Yahoo API's endpoint (https://developer.yahoo.com/weather/) and concatenate the zip code and country to it using the synapse get-property XPath expression:

    Code Block
    concat('?q=select%20*%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D%22',syn:get-property('uri.var.zipcode'),',',syn:get-property('uri.var.country'),'%22)&format=json')

  14. Similarly, add another property mediator with the following values. This is an HTTP transport property that appends its value to the address endpoint URL. Once you are done, save the sequence.

    Property NameNew Property
    New Property NameREST_URL_POSTFIX
    Value TypeExpression
    Value ExpressionSet the value of the property mediator that you created earlier as get-property('YQL')
    Property ScopeAxis2

  15. Save the sequence.
  16. Right-click on the sequence and click Commit File to push the changes to the Publisher server.
  17. Log back in to the API Publisher, select the API that you created earlier and click the Edit link right next to its name to go to the edit wizard. 
  18. Navigate to the API's Implement tab, select the Enable Message Mediation check box and select the sequence that you created for the In flow. Next, click Manage and Save & Publish the API again.

    Tip

    Tip: It might take a few minutes for the sequence to be uploaded into the API Publisher. If it isn't there, please check again later.

  19. Open the API Store, subscribe to the API that you just published and generate the access tokens in order to invoke the API.
  20. Click the API Console tab of the API. It opens the integrated API Console using which you can invoke the API.
  21. Give the following values for the parameters and invoke the API. You can also give any other value of your choice.

    country

    usa

    zipcode95004

  22. Note the response that you get as a JSON object from Yahoo.

...

Note

Please note that following mediators are not usable within custom sequences since they are not supported by API Gateway custom medications.

  • Call mediator in non-blocking mode
  • Send mediator
Info
titleTruobleshooting

Use the following sample sequence to handle faults, when an invalid JSON request is sent.