2

I've created proxy for my REST API:

When you call target endpoint directly, example:

POST http://products.example.com/items 

you'll get response with location header like this

http://products.example.com/items/123131

But if I go through proxy:

POST http://example.apigee.net/products/v2/items 

then location header for newly created resource still points to target URL:

http://products.example.com/items/3423423

But I expected to get

http://example.apigee.net/products/v2/items/3423423

The question is: how to configure proxy to rewrite URLs in response to Proxy URLs?

Piotr Bochynski
  • 382
  • 2
  • 9

2 Answers2

1

Not sure if this helps much but I raised a very similar question to yours at How do you correctly return Location headers and do HATEOAS with Apigee?. We ended up needing to write our own policy which does a simple search and replace on the response received from the target server. It would be nice if something was provided out of the box.

Community
  • 1
  • 1
Michael
  • 62
  • 11
0

Apigee proxy allows you to add policies in the response part of a flow. Example below:

<Flows>
        <Flow name="myFlow">
            <Description></Description>
            <Request/>
            <Response>
               <Step>
                    <Name>ModifyLocationHeaderPolicy</Name>
               </Step>
            <Response/>
        </Flow>
</Flows>

I suggest you to add a javascript or python or java callout policy which will read the Location header of the response and re-write it. Something to the effect like below in Javascript

locationHeader = context.getVariable("message.header.Location");
// modify it
 context.setVariable("message.header.Location", locationHeader);
Santanu Dey
  • 2,900
  • 3
  • 24
  • 38
  • Thank you. I hoped that I don;t have to code it manually. Is my problem so rare, that there is no built-in policy for that? What about HATEOAS? Nobody use it with apigee? And what about this statement from apigee: " Use out-of-the-box policies where possible, and avoid the temptation to code all of your API proxy logic in JavaScript. Even though Apigee Edge leverages compiled JavaScript to improve performance, it is unlikely that JavaScript will perform as well as Policies." Source: http://apigee.com/docs/api-services/content/programming-api-proxies-javascript – Piotr Bochynski Sep 11 '14 at 20:43
  • @Pitor Bochynski - I completely agree to your points here. It is not a rare situation. – Santanu Dey Sep 12 '14 at 05:30