You can do the same using a dynamic sequence as well. For that you will need to make the below changes to the sequence explained in Resource-based routing. However all the versions needs to be defined and handled separately whereas the above sequence will dynamically populate any version which you pass in the header.
|title||Expand to see the sample sequence...|
<sequence name="dynamic_ep" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<!-- The property which is retrieved as get-property('To')" stores the request URI for the API. Based on this value we will determine the endpoint which the request needs to be routed to.-->
<!-- We are then assigning the endpoint which we need to route to in a property named service_ep in this step -->
<property name="service_ep" value="https//first.backend.url/1.0.0/customers/>
<property name="service_ep" value="https//first.backend.url/2.0.0/customers/"/>
<!– add endpoints as needed –>
<property name="service_ep" value="https//first.backend.url/1.0.0/customers/"/>
<!–default endpoint if required. However there should be a matching resource–>
<!-- Next we need to store this endpoint in a header named To as shown below -->
<header name="To" expression="get-property('service_ep')"></header>
<property expression="get-property('service_ep')" name="ENDPOINT_ADDRESS"></property>
<!–Please note that "ENDPOINT_ADDRESS" (additional) property is defined here in order to populate
destination address for statistics (API Usage by Destination). –>
Working with properties
The Property Mediator has no direct impact on the message, but rather on the message context flowing through Synapse.
<property name="string" [action=set|remove] [type="string"] (value="literal" | expression="xpath") [scope=default|transport|axis2|axis2-client] [pattern="regex" [group="integer"]]>
For a list of the types of properties which you are able to work with, see Properties Reference. All properties which need to be set follow the same basic syntax. The following are some examples of setting properties.
|Table of Contents|
Setting a content type
<sequence xmlns="http://ws.apache.org/ns/synapse" name="property_sequence">
<property name="ContentType" value="text/xml" scope="axis2"/>