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/.
Map the Parameters of your Backend URLs with the API Publisher URLs
This tutorial uses the WSO2 API Manager Tooling Plug-in.
This tutorial explains how to map your backend URLs to the pattern that you want in the API Publisher. Note the following:
- The URL pattern of the APIs in the Publisher isÂ
http://<hostname>:8280/<context>/<version>/<API resource>
. - You can define variables as part of the URI template of your API's resources. For example, in the URI templateÂ
/business/{businessId}/address/
,ÂbusinessId
 is a variable. - The variables in the resources are read during mediation runtime using property values with the "
uri.var.
" prefix. For example, this HTTP endpoint gets the businessId that you specify in the resourceÂhttp://localhost:8280/businesses/{uri.var.businessId}/details
. - The URI template of the API's resource is automatically appended to the end of the HTTP endpoint at runtime. You can use the following mediator setting to remove the URL postfix from the backend endpoint:Â
<property name="REST_URL_POSTFIX" scope="axis2" action="remove"/>
.Â
We do the following mapping in this tutorial:
Before you begin, note that a mock backend implementation is set up in this tutorial for the purpose of demonstrating the API invocation. If you have a local API Manager setup, save this file in the <APIM_HOME>/repository/deployment/server/synapse-configs/default/api
 folder to set up the mock backend.Â
Log in to the API Publisher, design a new API with the following information, click Add and then click Next:Â Implement >.
Field Sample value Name TestAPI Context /test Version 1.0.0 Visibility Public Resources URL pattern /business/{businessId}/address/ Request types GET
The Implement tab opens. Give the information in the table below.Â
Field Sample value Endpoint type HTTP/REST endpoint Production endpoint http://localhost:8280/businesses/{uri.var.businessId}/details
Sandbox endpoint http://localhost:8280/businesses/{uri.var.businessId}/details
Click Next: Manage > to go to theÂ
Manage
 tab, select theÂGold
 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
).<sequence xmlns="http://ws.apache.org/ns/synapse" name="TestSequence"> <property name="REST_URL_POSTFIX" scope="axis2" action="remove"/> </sequence>
Download and install the WSO2 API Manager Tooling Plug-in if you have not done so already. Open Eclipse by double clicking theÂ
Eclipse.app
 file inside the downloaded folder.Â- 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.
On the dialog box that appears, click WSO2 APIManager and click OK.
- On the APIM perspective, click the Login icon as shown below.
- On the dialog box that appears, enter the URL, username and password of the Publisher server.
- On the tree view that appears, expand the folder structure of the existing API.
- Right-click on theÂ
in
 sequence folder and click Import Sequence to import the sequence you create above. - Browse to the
TestSequence.xml
file you created in step 4. Your sequence now appears on the APIM perspective. Right-click on the imported sequence and click Commit File to push the changes to the Publisher server.
Log back into the API Publisher, click Edit and go to the Implement tab. Select the Enable Message Mediation check box and engage theÂ
In
 sequence that you created earlier.TestSequence.xml removes the URL postfix from the backend endpoint, since the URI template of the API's resource is automatically appended to the end of the URL at runtime. Therefore the request URL is modified by adding this sequence to the In flow.
- Save and Publish 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.
Click the View Subscriptions button when prompted. The Subscriptions tab opens.
Click the Production Keys tab and click Generate Keys to create an application access token. If you have already generated a token before, click Re-generate to renew the access token.Â
Click the API Console tab of your API.
Note that the
businessId
is added in the UI as a parameter. Give abusinessId
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
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.Â