Cloud Blog

Multiple endpoints per API

Dynamic Endpoint functionality of API Cloud allows you to dynamically pick the backend to which each call is routed based on the call’s properties.

For example, suppose you have an API that has two resources /countries and /regions:

And suppose the actual implementation of the functionality is at two different backends. /countries is implemented by first.backend.url and /regions by something.different.url.

Fear not, this is fairly easy to implement with API Cloud. You simply need to select Dynamic Endpoint as the Endpoint Type and upload the In Flow sequence that defines the rules to route the traffic:

In our sample scenario, the In Flow sequence might look similar to this:

<sequence name=”dynamic_ep” trace=”disable” xmlns=”http://ws.apache.org/ns/synapse“>
    <switch source=”get-property(‘To’)”>
        <case regex=”.*/countries/.*”>
            <property name=”service_ep” value=”https//first.backend.url“/>
        </case>
        <case regex=”.*/regions/.*”>
            <property name=”service_ep” value=”https://something.different.url“/>
        </case>
        <!– add endpoints as needed –>
        <default>
            <property name=”service_ep” value=”http://some.default.url”/>
            <!–default endpoint if required. However there should be a matching resource–>
        </default>
    </switch>
    <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). –>
</sequence>

You can obviously define more complex rules if needed.

Do you have multiple backend services that need to become a single API? Dynamic Endpoints can get you going!

 

Leave a Reply

Your email address will not be published. Required fields are marked *


Categories

Recent Posts

Most Popular Posts

Twitter Facebook LinkedIn