FoxyCart Examples

Example 1

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:

  1. Call the user resource to determine the default shopping cart
    GET http://api-multi-request.demos.mikestowe.com/foxy/api/users/1
  2. Locating the _links.fx:default_store.href, call the store resource
    GET http://api-multi-request.demos.mikestowe.com/foxy/api/stores/66
  3. Locating the _links.fx:carts.href, call the carts resource
    GET http://api-multi-request.demos.mikestowe.com/foxy/api/stores/66/carts

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.

Example 2

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.

  1. Call the user resource to determine the default shopping cart
    GET http://api-multi-request.demos.mikestowe.com/foxy/api/users/1
  2. Locating the _links.fx:default_store.href, call the store resource with "/carts" appended
    GET http://api-multi-request.demos.mikestowe.com/foxy/api/stores/66/carts

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"]
  }
]

Example 3

In this example we just want to get the store name, email, and url (not all the extra data or links).

  1. Get All Store Data
    GET http://api-multi-request.demos.mikestowe.com/foxy/api/stores/66

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"]
  }
]