Layer7 API Management

  • 1.  Managing hateoas REST Api's

    Posted May 28, 2015 02:45 PM

    Hi,

     

    Is there an easy way to manage hateoas REST api's ? For this I would need some kind of find and replace assertion that scans the json response from the internal api and replaces any links in the response with the gateway equivalent ( which comes down to just replacing the base url every time )

     

    Any tips on how I can achieve this ?

     

     

    Thanks !



  • 2.  Re: Managing hateoas REST Api's
    Best Answer

    Posted May 28, 2015 03:32 PM

    Accidently I stumbled upon the answer myself. I was reading through the help files and apparently the "evaluate regular expression" assertion has a match and replace function, this was just what I needed to make it work! If you add it after your route via http assertion, it can scan the json and replace all the direct base urls with your gateway base urls.



  • 3.  Re: Managing hateoas REST Api's

    Posted May 28, 2015 04:06 PM

    Hello,

     

    Some containers/frameworks honor X-Forwarded-* headers.  For example, Spring MVC honors X-Forwarded-Host,  X-Forwarded-Proto,  X-Forwarded-Port.  If these are sent in, the framework will re-write the URL.  I tried this out by mapping incoming request context variables to the proper header values in the routing policy so that the back end service can do the correct thing.  Seems to work...

     

    I'd be interested in any feedback on this or other approaches to address this.  I'd also like to know what .NET people are doing with IIS.  My solution focuses on Java (specifically Spring MVC) + Tomcat containers.

     

    Thanks,

     

    Alejandro



  • 4.  Re: Managing hateoas REST Api's

    Posted May 28, 2015 04:15 PM

    So if I understand correctly, you create the x-forwarded headers in the policy based on the incoming context variables like request.http.uri etc and then send those headers to the backend, which automatically adjusts its links to the header values ? interesting ! Ofcourse this approach will only work for certain api setups. I think mine works in all cases, even if you don't have access to/can't edit the backend. Thanks for this, I've learned something new today