Extract query parameters
Extract query parameters, transform them, and add them to the response body.
The following example walks you through how to use an Inja template to find specific query parameters in a request, extract the parameter values, and to add these values to specific response headers.
This guide uses a subset of the supported transformation template attributes. To review all the attributes that you can set, see Templating language.
Before you begin
Follow the Get started guide to install Gloo Gateway, set up a gateway resource, and deploy the httpbin sample app.
Get the external address of the gateway and save it in an environment variable.
Extract query parameters
Create a RouteOption or VirtualHostOption resource with your transformation rules. In the following example, you use a regular expression to find the
foo
andbar
query parameters in the request path and to capture their values in thefoo
andbar
extractors. Then, the extractor values are added to the response headersfoo-response
andbar-response
.Send a request to the httpbin app and include the
foo
andbar
query parameters. Verify that you get back a 200 HTTP response code and that the value of thefoo
andbar
query parameters were added to the response headersfoo-response
andbar-response
.Example output:
Cleanup
You can remove the resources that you created in this guide.