...
Log in to the API Publisher, click the Add link, give the information in the table below and then click Implement.
Field Sample value Name TestAPI Context /test Version 1.0.0 Visibility Public Resources URL pattern /business/{businessId}/address/ Request types GET and OPTIONS
The
Implement
tab opens. Give the information in the table below.Field Sample value Implementation method Backend Endpoint type HTTP endpoint Production endpoint http://localhost:8280/businesses/{uri.var.businessId}/details
Click Manage to go to the
Manage
tab, select theGold
tier and publish the API.
As the API's resource is appended to its endpoint by Synapse at runtime, let's write a custom sequence to remove this appended resource.Copy the the following to a text editor and save the file in XML format (e.g.,
TestSequence.xml
).Code Block <sequence xmlns="http://ws.apache.org/ns/synapse" name="TestSequence"> <property name="REST_URL_POSTFIX" scope="axis2" action="remove"/> </sequence>
- Log in to the API Gateway's management console. If you are using WSO2 Cloud, the Gateway URL is
https://gateway.api.cloud.wso2.com/carbon/admin/login.jsp
. If you are using a local setup, the URL ishttps://localhost:9443/carbon
. You can see the username on the top right-hand corner of the API Publisher. After logging in, click the Browse menu under the Resources menu.
- When the API Gateway's registry opens, navigate to the registry path
/_system/governance/apimgt/customsequences/in
. This is because you want the custom sequence to be invoked in theIn
direction or the request path. Click Add Resource and upload the XML file of the sequence that you created earlier.
- Log back to the API Publisher, click the Edit link associated wit the API, navigate to the Manage tab, click the Sequences check-box and engage the sequence that you created to the API.
- Save the API.
You have created an API. Let's subscribe to the API and invoke it. Log in to the API Store and subscribe to the API.
When prompted, choose to go to the My Subscriptions page and generate an access token to invoke the API.
Click the API Console tab of your API.
Note that the businessId is added in the UI as a parameter. Give a businessId and click Try it out to invoke the API.
Note the response that you get. According to the mock backend used in this tutorial, you get the response as "Received Request."
In this tutorial, you mapped the URL pattern of the APIs in the Publisher with the endpoint URL pattern of a sample backend.