- Log in to the API Publisher.
- Select the option to design a new API and click Start Creating.
Give the information in the table below. To add resources, click the Add button.
Field Sample value Name WeatherLocation_API Context /weatherlocationVersion 1.0.0 Resources URL pattern {town} Request types GET
After the resource is added, expand its
GET
method , add the following parameterand note that a parameter by the name town is added under the resource. You use it to pass additional information the payload to the backend. Once done, click Implement.Parameter Name Description Parameter Type Data Type Required town Give the town name here Query String True In the Prototype sections under the Implement tab, click the implementation method as Inline.
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 resultand returns it as a JSON value.
Code Block mc.setProperty('CONTENT_TYPE', 'application/json'); var town = mc.getProperty('uri.var.town'); mc.setPayloadJSON('{ "Town" : "'+town+'"}');
Click the Deploy as a Prototype button.
Go to the API Store, click the Prototyped APIs menu and note that the newly deployed API is listed there.
Click the API to open it and go to its API Console tab.
- Expand the GET method, give any value for the town (say London) and invoke the API.
Note the payload you gave as a JSON output in the response.
...