Entity batch/bulk processing Api

112 views
Skip to first unread message

Aleksey Chernoraenko

unread,
May 16, 2017, 1:37:59 PM5/16/17
to API Craft
Don't you mind guys share knowledge, info what is "state of the art", best practice for batch/bulk processing on api landscape?

For an example, api for sending one email: 

POST .../invitations  {... "email": "u...@example.com", ... }
<= 201 Created with location url

now I need to add support to send bulk emails

POST .../invitations/batch  [{ ... "email": "u...@example.com", ..}, {... "email": "u...@example.com", ..}, ...]  ?


--
Alexei

Michael Hibay

unread,
May 18, 2017, 10:25:43 PM5/18/17
to API Craft
The best way since there is no standard yet I can rip from a post I did on json apis discuss boards here... I'll include for convenience.  The format is Json API.

The way I would approach this is to create a resource which represents a bulk operation, maybe not even on the errand resource. I wouldn't concern myself with what the operation is, the resource representation should give that information.

/bulktransactions/.....

That way your payload could be something like this:

{
  "data": {
    "type": "bulktransaction",
    "attributes": {
      "resources": [{"type":"errands"}],
      "operations": [
        {"id":123,"method":"PATCH", "payload":1},
        {"id":124,"method":"PATCH", "payload":1},
        {"id":125,"method":"PATCH","payload":1}
      ],
      "payload":[
        {"id":1,
          "value":{
            "data": {
              "type": "errands",
              "attributes": {
                "dirty": true
              }
            }
          }
        }
      ]
    }
  }
}

You could return a location header for the bulk transaction resource itself, and get all the info and updates you needed from there.

RestIsSexy

unread,
Oct 29, 2017, 11:47:45 PM10/29/17
to API Craft
Hi Michael,
your approach is very flexible but I wonder if its makes the bulk operation less discover-able and intuitive ? I also worry that it might open the door to threats. Thoughts ?
Reply all
Reply to author
Forward
0 new messages