How to send response from proxy end point without hitting target?

Not applicable

I have a scenario where my response is created based on some fields given in request, without the need of forwarding the request to backend. Can someone suggest how to do this?

eg: if http://myorg.apigee.com/whats/here is my request, then my response will be

"Whats here is this"

so basically my response depends on path params in this case ("is this is a static value")

PS: the example may be terrible but couldn't come up with anything better

Solved Solved
0 7 5,716
1 ACCEPTED SOLUTION

What you need to do is create an endpoint as a null target. That way when the call comes in it will not be forwarded to an actual backend rather will be served from Apigee itself. And then you can assign/manipulate the response via policies.

You can find an example of this here : https://community.apigee.com/questions/10437/apige...

Sarthak

View solution in original post

7 REPLIES 7

What you need to do is create an endpoint as a null target. That way when the call comes in it will not be forwarded to an actual backend rather will be served from Apigee itself. And then you can assign/manipulate the response via policies.

You can find an example of this here : https://community.apigee.com/questions/10437/apige...

Sarthak

@sarthak

Thanks for the prompt reply. I am actually looking for a way to set this for a particular request in a proxy. The example sets the base path as no target. I already have a basepath for most of the requests. I need to respond from apigee for some specific request.

I presume conditional flows and route rule both can be used to redirect flows to seperate target points but how to set no target for a specific request?

Hope I don't have to create a seperate proxy for these kind of requests

Route rule tag without a target endpoint means no target.

Route with just a condition tag and not target endpoint - means conditional null target. This may work for your case.

Route rule is applied outside the flows right? so how to set a response in that case? even an assign message policy needs to be applied on a flow.

I need a way to give response from proxy end itself without hitting any backend

Create a flow (containing request/response) with a condition. Use the same condition on the route rule too. Shown below

  <Flow name="cacheAttributes">
    <Description/>
    <Request>
        <Step>
            <Name>do-something</Name>
        </Step>
    </Request>
    <Response>
        <Step>
            <Name>add-response</Name>
        </Step>
    </Response>
    <Condition>(proxy.pathsuffix MatchesPath "/attributes")</Condition>
</Flow>     
...
....
...
<RouteRule name="cacheAttributes">
    <Condition>(proxy.pathsuffix MatchesPath "/attributes")</Condition>
</RouteRule>              

The Execution will be Request Steps - > Route Rule -> Response steps. In you response add the data you want. The route rule does not contain TargetEndpoint tag hence a null target.

You can dynamically choose null target too.

<RouteRule name="nullTarget">
    <Condition>(routeTo = "null.target")</Condition>
</RouteRule>

Here the chose of null target based on value of the variable 'routeTo'

Let me know if this helps

@sriki77

Thanks mate! It worked like a charm!!!

removing the <TargetEndpoint> tag did the trick.

Although, it is not accepting null.target inside the TargetEndPoint tag.

We cannot specify it in condition as it already has the condition from the flow. So where do we set the routeTo variable?

I know its not necessary, but asking for information sake

Not applicable

@sarthak @sriki77

I think I found a way. I created a conditional flow to filter my specific request, on which I applied a 'raise fault' policy. In its payload, I am setting the desired response. This response is sent whenever a request validates to true in that conditional flow.

Let me know if this is the right approach or if there is a better approach.

I have some doubts as the policy, by its name, is used to raise fault. Although it is not raising any fault in my case, I am using this as my need is to not hit any backend API and make APIGEE respond directly.

This works, but is it the right way?