Before you start with this tutorial you should finish the Getting Started Guide.
Membrane assigns incoming requests to APIs. The APIs process the requests and route them to backend targets. The API from the Getting Started accepted all requests from port 2000
and routed them to https://api.predic8.de
.
Now we make the routing more specific by adding a second API.
Go to the tutorial/rest
folder in a terminal window and start there Membrane.
cd tutorial/rest
./service-proxy.sh
First add a <path>
to the API inconf/proxies.xml
:
<api port="2000">
<path>/shop</path>
<beautifier/>
<target url="https://api.predic8.de"/>
</api>
A request to http://localhost:2000/shop/
still works. But if the path does not match an error message is returned.
❯ curl localhost:2000
{"error":"This request was not accepted by Membrane. Please check HTTP method and path."}
Next add a secound API on the same port 2000
with a different path.
<api port="2000">
<path>/shop</path>
<target url="https://api.predic8.de" />
</api>
<api port="2000">
<path>/restnames</path>
<target url="http://www.thomas-bayer.com" />
</api>
Requests are now routed depending on the path to different backends. Try the following requests:
curl localhost:2000/shop
curl "localhost:2000/restnames/name.groovy?name=Pia"
Both should be working. But if a request does not match one of the paths like:
❯ curl localhost:2000
{"error":"This request was not accepted by Membrane. Please check HTTP method and path."}
an error will be retured.