This documentation is for WSO2 API Manager 1.9.1 View documentation for the latest release.
Map the Parameters of your Backend URLs with the API Publisher URLs - API Manager 1.9.1 - WSO2 Documentation
||
Skip to end of metadata
Go to start of metadata

This tutorial explains how to map your backend URLs to the pattern that you want in the API Publisher. Note the following:
  1. The URL pattern of the APIs in the Publisher is http://<hostname>:8280/<context>/<version>/<API resource>.
  2. 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.
  3. 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.
  4. 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. 

  1. 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
    ResourcesURL pattern/business/{businessId}/address/
     Request types

    GET

  2. The Implement tab opens. Give the information in the table below. 

    FieldSample value
    Implementation methodBackend
    Endpoint typeHTTP endpoint
    Production endpoint

    http://localhost:8280/businesses/{uri.var.businessId}/details

  3. Click 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.

  4. 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>
  5. 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 is https://localhost:9443/carbon. You can see the username on the top right-hand corner of the API Publisher.
  6. After logging in, click the Browse menu under the Resources menu. 
     

  7. 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 the In direction or the request path. 
  8. Click Add Resource and upload the XML file of the sequence that you created earlier.
     

  9. 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.
     
  10. Save the API.
    You have created an API. Let's subscribe to the API and invoke it.
  11. Log in to the API Store and subscribe to the API.

  12. When prompted, choose to go to the My Subscriptions page and generate an access token to invoke the API.

  13. Click the API Console tab of your API.
     

  14. Note that the businessId is added in the UI as a parameter. Give a businessId and click Try it out to invoke the API.
     

  15. 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. 

  • No labels