Request Body

Understand how the API payload is integrated with the integration request.

Payload mapping

Query strings and path parameters are pretty simple to isolate and transform. However, the complexity increases exponentially when we look into the API payload. The request body could be a complex JSON, XML, or just a blob. It’s challenging to extract details from it and transform them per the target API's requirements. Let’s now dig deeper to understand the immense potential of this feature.

API Gateway simplifies this process using Apache Velocity templates, which provide a concise syntax for data transformation. The templates are intuitive, learnable simply by reading a few lines of code.

Velocity template example

Let’s check out an example where we use a Velocity template to construct a payload of the API integration. The below code uses an HTTP integration with a public API for IP geolocation. The API returns the geolocation for any IP address in the input payload. The integration pulls the source IP address from the request and passes it on to the public API to get the geolocation of the server running this code.

Create a free account to view this lesson.

By signing up, you agree to Educative's Terms of Service and Privacy Policy