Skip to content

Mapping the Parameters of your Backend URLs with the API Publisher URLs

This tutorial explains how to map your backend URLs to the pattern that you want in the API Publisher.

Note

  • TheĀ URL pattern of the APIs in the Publisher is http://<gateway-hostname>:<gateway-port>/<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/{id}/details/ , id is a variable.

Let's do the following API resource to backend mapping in this tutorial as an example.

<gateway-url>/business/{id}/details  --->  <backend-url>/api/business/{id}/info
  1. Log in to the API Publisher, Create a new API with the following information.

    Field Sample value
    Name TestAPI
    Context /test
    Version 1.0.0
    Endpoint https://httpbin.org/anything

    Info

  2. Go to Resources tab under the API Configurations and add a resource with the following parameters.

    Field Value
    HTTP Verb /business/{id}/details
    URL pattern GET
  3. Delete the auto generated wildcard /* resources. Otherwise all the requests will go to them.

  4. Then Save and deploy. Final API will look as follows.

  5. Copy the the following to a text editor and save the file in XML format.
    (e.g., TestSequence.xml ).

        <property name="NEW_URL" value="/business/id/info" />
        <rewrite inProperty="NEW_URL" outProperty="NEW_URL">
            <rewriterule>
                <action type="replace" regex="id" xpath="get-property('uri.var.id')" fragment="path" />
            </rewriterule>
        </rewrite>
        <property name="REST_URL_POSTFIX" expression="get-property('NEW_URL')" scope="axis2" />
    

    Info

    • This sequence does the required mapping at synapse runtime.
    • The sequence is self explanetory and you can customize it for your own requirements.
  6. Go to Policies tab and create a custom policy with any name using the above sequence. ( We use Custom Policy as the name here )

  7. Add the Custom Policy to the Request Flow of /business/{id}/details resource. Then Save and deploy.

    Now parameter mapping should work as intended and let's test this out.

  8. Click the Try Out tab of and try /business/{id}/details.

In this tutorial, you mapped the URL pattern of the APIs in the Publisher with the endpoint URL pattern of a sample backend.