Read Path Param in wso2 ESB 4.8.1
We can read 'path' parameter in WSO2 ESB. To do so , we can use "uri-template" attribute of <resource> tag.
Suppose we need to read parameter from an API like "example.com/api/getStatus/{some category}/{some id}.json", So we should configure API in ESB as follows :
STEP 1:
Give the first static part of the URL as the 'context' of <api> tag
Example
<api xmlns="http://ws.apache.org/ns/synapse" name="sample-API" context="/api/getStatus">
STEP 2:
Give the remains part of the URL as the 'uri-template' <resource> tag but dynamic value may write inside {} brackets.
Example
<resource methods="GET" uri-template="/{category}/{id}.json">
How to read Parameter
We can read url path param by using the 'expression' of <property> tag. In <property> tag ,the variable name should same as mentioned inside {} brackets in <resource> tag.
Example
<property name="uri.var.category" expression="getproperty('uri.var.category')"></property>
<property name="uri.var.id" expression="get-property('uri.var.id')"></property>
We can read 'path' parameter in WSO2 ESB. To do so , we can use "uri-template" attribute of <resource> tag.
Suppose we need to read parameter from an API like "example.com/api/getStatus/{some category}/{some id}.json", So we should configure API in ESB as follows :
STEP 1:
Give the first static part of the URL as the 'context' of <api> tag
Example
<api xmlns="http://ws.apache.org/ns/synapse" name="sample-API" context="/api/getStatus">
STEP 2:
Give the remains part of the URL as the 'uri-template' <resource> tag but dynamic value may write inside {} brackets.
Example
<resource methods="GET" uri-template="/{category}/{id}.json">
How to read Parameter
We can read url path param by using the 'expression' of <property> tag. In <property> tag ,the variable name should same as mentioned inside {} brackets in <resource> tag.
Example
<property name="uri.var.category" expression="getproperty('uri.var.category')"></property>
<property name="uri.var.id" expression="get-property('uri.var.id')"></property>
No comments:
Post a Comment