Layer7 API Management

  • 1.  How to get Layer 7 to forward query parameters and wild card routes to back end?

    Posted Mar 06, 2017 09:02 PM

    Hi Layer 7/CA API team,

     

    I have a back end url similar to the following:

     

    https://backend.com/api/

     

    I have a Layer 7 front end URL similar to the following:

     

    https://dmz.com/hello/goodbye/matthew/*

     

    What I essentially want is for any thing in the wild card to be forwarded unconditionally to my back end; i.e:

     

    https://backend.com/api/{$wildcard}*

     

    So for example:

     

    https://dmz.com/hello/goodbye/matthew/foo/bar/baz --> https://backend.com/api/foo/bar/baz

    https://dmz.com/hello/goodbye/matthew/foo/?bar=baz --> https://backend.com/api/foo/?bar=baz

     

    What I don't want to do is configure the legal hierarchy or the legal query parameter names upfront. I want Layer 7 to forward everything in the wildcard unconditionally to the back end no questions asked.

     

    Does anyone know how I can make this happen?

     

    ----------

     

    I saw another question here advising to use ${request.url.path}. I don't find it appropriate for two reasons: 1) it will end up forwarding to https://backend.com/api/hello/goodbye/matthew/foo/bar/baz for example; I could regex it out in the backend, but my backend can be accessed outside of Layer 7.  And 2) It doesn't pass along the query params.

     

    The same link suggested using ${request.http.parameter.<name>} to get the query parameters, but this won't work for me because I want Layer 7 to pass back all query paremeters unconditionally to the backend without me having to specify upfront which are allowed or not.

     

    Thanks and best regards,

     

    Matthew



  • 2.  Re: How to get Layer 7 to forward query parameters and wild card routes to back end?
    Best Answer

    Broadcom Employee
    Posted Mar 07, 2017 10:11 AM

    Hi Matthew,

     

    For the query parameters I believe what you are looking for is: ${request.url.query}

    ref: Transport Layer Context Variables - CA API Gateway - 9.2 - CA Technologies Documentation 

     

    You would use it like this in a routing assertion



  • 3.  Re: How to get Layer 7 to forward query parameters and wild card routes to back end?

    Posted Mar 07, 2017 07:24 PM

    Hi @dasjo2,

     

    Thank you very much; I have tested ${request.url.query} and can confirm that it works.

     

    Would you have any idea if there was a way to do the following:

    1) Obtain the `/hello/goodbye/matthew/foo/bar/baz` portion via ${request.url.path}

    2) Do some kind of substring from this and `/hello/goodbye/matthew` in order to capture `/foo/bar/baz`

     

    If so, I could put that into a context variable and pass that through.

     

    Best regards,

     

    Matthew Moisen



  • 4.  Re: How to get Layer 7 to forward query parameters and wild card routes to back end?

    Broadcom Employee
    Posted Mar 08, 2017 10:19 AM

    Hi Matthew,

     

    Glad to help. It looks like you got the other part of the problem resolved with the below, very nice solution.

    Let me know if there is anything else I can assist with.

     

    Regards,

    Joe



  • 5.  Re: How to get Layer 7 to forward query parameters and wild card routes to back end?

    Posted Mar 07, 2017 07:47 PM

    Sweet I think I found out how to resolve the dynamic URL:

     

    In the Layer 7 Policy Manager:

    1) search for "Set Context Variable" and drag it out. Set the name as "url" and the value as "${request.url}"

    2) type "xpath" into the search and then drag the "Evaluate Request XPath" right below the Context Variable you set above.

    In the "xpath" field, type in "substring-after($url, '/hello/goodbye/matthew')", replacing "hello/goodbye/matthew" with the name of your end point. This will set any value beyond /hello/goodbye/matthew/ to a variable.

     

    In the "variablePrefix" box type in "newUrl" or something similar. The value will be set to {$newUrl.result}.

     

    3) In the "Route via" assertion, change the URL to "https://backend.com/api/${newUrl.result}${request.url.query}"

     

    Best regards,

     

    Matthew



  • 6.  Re: How to get Layer 7 to forward query parameters and wild card routes to back end?

    Broadcom Employee
    Posted Mar 08, 2017 11:50 AM

    Hello Matthew,

     

    If I understand your question correctly, I am actually doing the same thing in one of my policies, I have frontend incoming URLs:

    https://gateway.ca.com:8443/service/A/parameter?m=1...

    https://gateway.ca.com:8443/service/B/parameter?m=3...

    https://gateway.ca.com:8443/service/C/parameter?m=1...

     

    Depending on the whether we have '/A' or '/B' in the uri these requests will be routed to https://backend.com/1/A/parameter?m=1 , https://backend.com/2/B/parameter?m=1 or https://backend.com/2/C/parameter?m=1 respectively.

     

    I use one routing assertion in my policy dynamically changing the uri depending on whether we have '/A' , '/B' or  '/C' in the frontend URL because that determines whether we are routing to https://backend.com/1/... , https://backend.com/2/... or https://backend.com/3/... 

     

    As an exampIe, when a request comes in with https://gateway.ca.com:8443/service/A/parameter?m=1, I use ${request.http.uri} to capture uri '/service/A/parameter' , do a simple compare to see if that uri contains '/A/' , '/B/' or '/C/'  (you can use other logic) and then use the "evaluate regular expression" assertion on the captured uri to replace the '/service/' with a '/1/' ( I can also just drop the '/service/' by replacing it with a blank in the assertion, if I dont need to replace), and then append the modified uri and query to the backend route. The resulting modified URI and query will be "/1/A/parameter?m=1 ".

     

    ${backendUrl}$(modifiedUri}${request.url.query}

     

    I hope this builds on Joe's help on this.

     

    Wesley