Hi,
I'd like to route two API endpoints to the same backend REST endpoint only with different policies attached.
Imagine an email service with the resources (this is just an example, please dont question sensibility)
/headers
/posts
In the backend there is only the resource /posts.
So the /headers API should call /posts in the backend but remove the message bodies by using a policy.
The /posts API should simply call /posts without any policies attached.
How can I accomplish that?
cheers
Benno
Solved! Go to Solution.
You can absolutely do that . There are 2 ways in which you can achieve this based on your requirement.
#1. If your resources are like /basepath/headers and /basepath/posts
You can have <BasePath>/basepath</BasePath> in your proxy definition and have different flows(http://apigee.com/docs/api-services/content/flow-configurations) for /headers and/ posts Using flows you can have flow(resource) specific policies . Using the route rule(http://apigee.com/docs/api-services/content/understanding-routes) you can point to the same target endpoint .
#2. If your resources are like /basepath1/headers and /basepath2/posts, you can have 2 endpoints (proxy definitions) and point to the same target endpoint using the route rules.
Adding to the comments above: TargetEndpoint definitions can also have conditional flows. If you put the policies needed to transform your back-end requests into conditional flows in the TargetEndpoint, then you can simply implement a conditional flow for /headers that removes the message body. For example,
<TargetEndpoint name="whatever">
... stuf ...
<PreFlow name="PreFlow">
<Request/>
<Response/>
</PreFlow>
<Flows>
<Flow name="headerHandler">
<Condition>proxy.pathSuffix = "/headers"</Condition>
<Step><Name>StripBody</Name></Step>
</Flow>
</Flows>
<PostFlow name="PostFlow>
<Request/>
<Response/>
</PostFlow>
... more stuff ...
</TargetEndpoint>
All requests to this target will go through PreFlow and PostFlow unchanged. All requests will also go through the conditional flows unchanged except for requests to <basepath>/headers>, which will execute the conditional flow called "headerHandler" and strip the body from the message. A request to <basepath>/posts will not execute any conditional flows.
Does it have to be within the same proxy? If not just create a /posts and /headers proxy that route to the same target.
Thanks for your suggestion. But the point of an API is to have all resources and operations in one place?
You can absolutely do that . There are 2 ways in which you can achieve this based on your requirement.
#1. If your resources are like /basepath/headers and /basepath/posts
You can have <BasePath>/basepath</BasePath> in your proxy definition and have different flows(http://apigee.com/docs/api-services/content/flow-configurations) for /headers and/ posts Using flows you can have flow(resource) specific policies . Using the route rule(http://apigee.com/docs/api-services/content/understanding-routes) you can point to the same target endpoint .
#2. If your resources are like /basepath1/headers and /basepath2/posts, you can have 2 endpoints (proxy definitions) and point to the same target endpoint using the route rules.
Thanks for your answer! Case 1 is the relevant one. I tried that but cant get it to work somehow.
I added a conditional route for request path headers and a corresponding endpoint pointing to URL baseUrl/posts.
But that doesn't do it... The request is then sent to baseUrl/posts/headers.
You can find the answer here http://community.apigee.com/answers/1625/view.html . Hope that helps .
Adding to the comments above: TargetEndpoint definitions can also have conditional flows. If you put the policies needed to transform your back-end requests into conditional flows in the TargetEndpoint, then you can simply implement a conditional flow for /headers that removes the message body. For example,
<TargetEndpoint name="whatever">
... stuf ...
<PreFlow name="PreFlow">
<Request/>
<Response/>
</PreFlow>
<Flows>
<Flow name="headerHandler">
<Condition>proxy.pathSuffix = "/headers"</Condition>
<Step><Name>StripBody</Name></Step>
</Flow>
</Flows>
<PostFlow name="PostFlow>
<Request/>
<Response/>
</PostFlow>
... more stuff ...
</TargetEndpoint>
All requests to this target will go through PreFlow and PostFlow unchanged. All requests will also go through the conditional flows unchanged except for requests to <basepath>/headers>, which will execute the conditional flow called "headerHandler" and strip the body from the message. A request to <basepath>/posts will not execute any conditional flows.