There is REST Back-End end-point in Vehicle registration services as below

GET /car?name=prius HTTP/1.1
Host: localhost:8080
color: White

Company need to expose it 3rd part companies and above End-point should not change as internal services are using it.

GET /new-car/vitz/white/ HTTP/1.1
Host: localhost:8280

Server is contain with wso2 ESB or EI. Then you can it easily without using any property mediators even.

If you see mapping will align to as below

image

Here is the API synapse code

<?xml version="1.0" encoding="UTF-8"?>
<api context="/new-car" name="new-car-api" xmlns="http://ws.apache.org/ns/synapse">
   <resource methods="GET" protocol="http" uri-template="/{name}/{color}">

     <inSequence>
       <log level="custom">
         <property name="message" value="new-car-api is called"/>
       </log>
       <!-- If you need to get to property you -->
       <!-- property name="carColor" expression="get-property('uri.var.color')"></property-->
      <header name="color" expression="get-property('uri.var.color')"  scope="transport"/>     
       <send>
         <endpoint key="car-end-point"/>
       </send>
     </inSequence>
     <outSequence>
       <log level="custom">
         <property name="property_name" value="new-car-api - out is hitted"/>
       </log>
       <send/>
     </outSequence>
     <faultSequence/>
   </resource>
</api>


Here is the car-end-point

<?xml version="1.0" encoding="UTF-8"?>
<endpoint name="car-end-point" xmlns="http://ws.apache.org/ns/synapse">
   <http method="get" trace="disable" uri-template="http://localhost:8080/car?name={uri.var.name}"/>
</endpoint>

Here we are testing

image

image

In above sample we did not testing Query parameter. If you need to retrieving model as Query parameter and pass it to the name you do the below modifications

Resource will have below modification

<resource methods="GET" protocol="http" uri-template="/{name}/{color}?model={model}">

Add new property before call end point

<property name="uri.var.model" expression="$url:model"/>

Update endpoint as below

<http method="get" trace="disable" uri-template="http://localhost:8080/car?name={uri.var.name}-{uri.var.model}"/>

Testing again

image

In Summary you can get URL parameter or URL value as below.

<resource methods="POST GET" uri-template="/{val1}/test/?q1={v1}">
<property name="uri.var.q1" expression="$url:q1"></property>
<property name="uri.var.val1" expression="get-property('uri.var.val1')"></property>

1

View comments

I am
I am
Archives
Total Pageviews
Total Pageviews
2 0 5 7 7 0 6
Categories
Categories
Loading