In this example we are going to make three separate calls with an end goal of getting the number of carts currently active at a store:
To use the chain, we would simply make one call via POST, as such:
http://api-multi-request.demos.mikestowe.com/foxy/api/multirequest
[
{
"doOn": "always",
"href": "/users/1",
"method": "get",
"data": {},
"return": ["_links.fx:default_store.href"]
},
{
"doOn": "200",
"href": "${body._links.fx:default_store.href}",
"method": "get",
"data": {},
"return": ["_links.fx:carts.href"]
},
{
"doOn": "2*",
"href": "$body._links.fx:carts.href",
"method": "get",
"data": {},
"return": ["total_items"]
}
]
You'll notice that unlike the previous calls, we are only returning back the data requested, the two links, and then the total_items field from the /stores/66/carts resource. To return additional items, we can simply add them in the array with a dot object syntax (item.child.child) or change the value of "return" to (bool) true to return back all data.
In this example, we will do the same thing - however we will be hard coding the /carts link (making this resource inflexible as if it changes, our method breaks). This is not a good practice, but is being done to show variable placement within a string.
To use the chain, we would follow a similar approach, appending "/carts" to the second link's href:
http://api-multi-request.demos.mikestowe.com/foxy/api/multirequest
[
{
"doOn": "always",
"href": "/users/1",
"method": "get",
"data": {},
"return": ["_links.fx:default_store.href"]
},
{
"doOn": "200",
"href": "${body._links.fx:default_store.href}/carts",
"method": "get",
"data": {},
"return": ["total_items"]
}
]
In this example we just want to get the store name, email, and url (not all the extra data or links).
However, with the chain (even thought it's just one request) we can control the data returned:
http://api-multi-request.demos.mikestowe.com/foxy/api/multirequest
[
{
"doOn": "always",
"href": "/stores/66",
"method": "get",
"data": {},
"return": ["store_name", "store_email", "store_url"]
}
]