Chain requests in Insomnia
Create at least two requests, send one to get a response, then configure a template tag in the second request to reuse a value from the first request’s response.
Prerequisites
Create and configure a collection
- Create a new collection.
- Import the KongAir Flights requests.
- Add the following content to the base environment:
{ "base_url": "https://api.kong-air.com" }
Send the first request
In the KongAir collection you configured in the prerequisites, open the Get KongAir planned flights request and click Send to get a list of flights. We can reuse content from the response in the next request.
Edit the second request
Open the Fetch more details about a flight request. This request requires a flight number in the path. We’ll use a template tag to get a flight number from the list of flights from the previous request.
Remove the _.flightNumber
placeholder and start typing response
in its place. When a drop-down list appears, click Response > Body Attribute.
Configure the template tag
Click the template tag, and configure it with the following values to get the flight number for the first flight on the list:
Field |
Value |
---|---|
Function to Perform | Response |
Attribute | Body Attribute |
Request | GET Get KongAir planned flights |
Filter |
$.[0].number
|
Trigger Behavior | Never |
Once this is done, we can see the live preview of the value (KA0284 in this example). We can then click Done to apply the changes.
Send the second request
Click Send on the Fetch more details about a flight to get the information about the first flight on the list. This is the response:
{
"aircraft_type": "Boeing 777",
"flight_number": "KA0284",
"in_flight_entertainment": true,
"meal_options": [
"Chicken",
"Fish",
"Vegetarian"
]
}