Read more

murdho/rack-cargo: Batch requests for Rack APIs

Henning Koch
August 01, 2017Software engineer at makandra GmbH

rack-cargo Show archive.org snapshot gives your API a new /batch route that lets clients perform multiple API calls with a single request.

Illustration UI/UX Design

UI/UX Design by makandra brand

We make sure that your target audience has the best possible experience with your digital product. You get:

  • Design tailored to your audience
  • Proven processes customized to your needs
  • An expert team of experienced designers
Read more Show archive.org snapshot

The batched calls are resolved internally and are then returned as an array of responses:

// This is batch request payload:
{
    "requests": [
        {
            "name": "order",
            "path": "/orders",
            "method": "POST",
            "body": {
                "address": "Home, 12345"
            }
        },
        {
            "name": "order_item",
            "path": "/orders/{{ order.uuid }}/items", // <-- here
            "method": "POST",
            "body": {
                "title": "A Book"
            }
        },
        {
            "name": "payment",
            "path": "/payments",
            "method": "POST",
            "body": {
                "orders": [
                    "{{ order.uuid }}" // <-- and here
                ]
            }
        }
    ]
}

// This is a possible response:
[
    {
        "name": "order", // <-- "order" part of "order.uuid"
        "status": 201,
        "headers": {},
        "body": {
            "uuid": "bf52fdb5-d1c3-4c66-ba7d-bdf4cd83f265", // <-- "uuid" part of "order.uuid"
            "address": "Home, 12345"
        }
    },
    {
        "name": "order_item",
        "status": 201,
        "headers": {},
        "body": {
            "uuid": "38bc4576-3b7e-40be-a1d6-ca795fe462c8",
            "title": "A Book"
        }
    },
    {
        "name": "payment",
        "status": 201,
        "headers": {},
        "body": {
            "uuid": "c4f9f261-7822-4217-80a2-06cf92934bf9",
            "orders": [
                "bf52fdb5-d1c3-4c66-ba7d-bdf4cd83f265"
            ]
        }
    }
]
Henning Koch
August 01, 2017Software engineer at makandra GmbH
Posted by Henning Koch to makandra dev (2017-08-01 14:29)