Route requests to internal proxies for reusable functionality across multiple APIs and content-based routing.
Note: You can test these requests using the provided HTTP file or cURL snippets.
- Navigate to the
examples/routing-traffic/internalproxydirectory. - Start Membrane by executing
membrane.sh(Linux/Mac) ormembrane.cmd(Windows). - Execute the following requests (alternatively, use the
requests.httpfile):
-
Normal Processing:
curl http://localhost:2000
Response:
Normal processing! -
Express Processing:
curl -X POST -d @express.xml http://localhost:2000
Response:
Express processing!
The main API endpoint configuration uses a <switch> element to change the url of <target> conditionally.
In this instance, we use internal proxies to encapsulate our plugins in separate routines,
this makes them reusable and cleans up our APIs:
<api port="2000">
<request>
<if test="//order[@express='yes']" language="xpath">
<destination url="internal://express"/>
</if>
</request>
<target url="internal://normal" />
</api>Note: InternalProxies can only be called from other proxies and APIs, not from external sources.
Two internal proxies handle different processing paths:
<internalProxy name="express">
<static>Express processing!</static>
<return/>
</internalProxy>
<internalProxy name="normal">
<static>Normal processing!</static>
<return/>
</internalProxy>