Bootstrap FreeKB - Broadcom API Gateway - Split Variable Assertion
Broadcom API Gateway - Split Variable Assertion

Updated:   |  Broadcom API Gateway articles

Certain variables are built into the API Gateway. One such variable is ${request.http.uri}. This variable will return the URI of the request. To demonstrate how this variable is commonly used, I setup http://www.freekb.net/Stage1 to return "Welcome to Stage 1".

 

  1. In the Policy Manager, select Publish Web API to create a REST service
  2. Give your service a unique name, such as myService.
  3. Target URL = The URL that requests will route out to (outbound), which would be http://www.freekb.net/${request.http.uri} in this example
  4. Gateway URL = The context root of the URL that requests will route into (inbound), which will be /Stage1 in this example
  5. Select Finish.

You can now get http://www.freekb.net/${request.http.uri} through the API Gateway. Let's say your API Gateway is configured with https://api.example.com. Since you defined /Stage1 as the endpoint for myService, you would use https://api.example.com/Stage1 to route requests through the API Gateway and onto http://www.freekb.net/${request.http.uri}. To put this another way, in this example, https://api.example.com/Stage1 is the inbound URL and http://www.freekb.net/${request.http.uri} is the outbound URL.

  • Inbound URL = https://api.example.com/Stage1
  • Outbound URL = http://www.freekb.net/${request.http.uri}

You should get the following.

 

As a bit of a more practial scenario, let's say you have multiple outbound URLs, such as.

  • http://www.freekb.net/foo
  • http://www.freekb.net/bar

In this scenario, you could add a wildcard to the inbound URL.

  • Inbound URL = https://api.example.com/Stage1/*

And then use the Split Variable assertion to split the ${request.http.uri} variable. In this example, the ${request.http.uri} variable is split at each forward slash.

 

If https://api.example.com/Stage1/foo is used as the inbound URL, then the following will be defined.

  • ${URIparts[0]} = /
  • ${URIparts[1]} = Stage1
  • ${URIparts[2]} = foo

Or if https://api.example.com/Stage1/bar is used as the inbound URL, then the following will be defined.

  • ${URIparts[0]} = /
  • ${URIparts[1]} = Stage1
  • ${URIparts[2]} = bar

 

The Route via HTTP assertion would then use the ${URIparts[2]} variable to know if the request should be forwarded onto http://www.freekb.net/foo or http://www.freekb.net/bar.

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter e8542a in the box below so that we can be sure you are a human.