This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

  1. Log in to the API Publisher.
  2. Select the option to design a new API and click Start Creating.
     
  3. Give the information in the table below. To add resources, click the Add button.

    Field Sample value
    Name Weather_API
    Context 
    /weather
    Version 1.0.0
    ResourcesURL pattern{town}
     Request types

    GET

  4. After the resource is added, expand its GET method, add the following parameter. You use it to pass additional information to the backend. Once done, click Implement.

    Parameter NameDescriptionParameter TypeData TypeRequired
    townGive the town name hereQueryStringTrue

  5. In the Prototype sections, click the implementation method as Inline.
     

  6. Expand the GET method and give the following as the script. It reads the payload that the user sends with the API request, converts it to JSON and returns the same value in the result.

    mc.setProperty('CONTENT_TYPE', 'application/json');
    var town = mc.getProperty('uri.var.town');
    mc.setPayloadJSON('{ "Town" : "'+town+'"}');

  7. Click the Deploy as a Prototype button.

  8. Go to the API Store, click the Prototyped APIs menu and note that the newly deployed API is listed there.
     

  9. Click the API to open it and go to its API Console tab.
     

  10. Expand the GET method, give any value for the town (say London) and invoke the API.
     
  11. Note the payload you gave as a JSON output in the response.
     

You have created an API with inline script, deployed it as a prototype and invoked it through the integrated API Console.

  • No labels