Layer7 API Management

  • 1.  Sorting input query string- parameters alphabetically

    Posted Sep 17, 2016 10:42 AM
    We have a API end point that has a GET method and takes in parameters P1, P2, P3 etc....We have a requirement to sort the parameters in the input query string alphabetically and then set their corresponding values against it.   For eg : Input url is https:// host:port/email=V1&coupon=V2&include=V3&channel=v4   We want to take the query string part of url and arrange it to a string  like below   channel=v4&coupon=V2&email=V1&include=V3  Can the above be done using a set of assertions and put within a policy fragment.

    Overall aim is to get the resulting string ( parameters arranged alphabetically ) and generate hash key out of that, then route to an end point that requires the hash key to be submitted in the header for authentication.


  • 2.  Re: Sorting input query string- parameters alphabetically
    Best Answer

    Posted Sep 19, 2016 11:51 AM
      |   view attached

    As far as sorting your inbound Params, you should be able to use something like this (also attached)

     

    this takes the inbound query params, loads it into an xml doc, then sorts via XSLT, then coverts it back to a string that can be used for the Next call to the backend.

     

    Im also assuming your input is like this: 

    https:// host:port/SomeService?email=V1&coupon=V2&include=V3&channel=v4

    Attachment(s)

    zip
    SortParams.xml.zip   1 KB 1 version


  • 3.  Re: Sorting input query string- parameters alphabetically

    Posted Sep 20, 2016 12:22 AM

    Thanks a lot for the idea, trying it now and trying to put it in as a policy fragment.

     

    Yes, you are correct, the input is :

    https:// host:port/SomeService?email=V1&coupon=V2&include=V3&channel=v4