batch_request_api icon indicating copy to clipboard operation
batch_request_api copied to clipboard

Migrating from arsduo/batch_api

Open dlackty opened this issue 6 years ago • 0 comments

Previously we used arsduo's batch_api gem to implement similar functionality but it wasn't maintained for a long while and never supports parallel requests.

One main different between that and batch_request_api is a slightly different payload format:

Request

{
  ops: [
    {method: "get",    url: "/patrons"},
    {method: "post",   url: "/orders/new",  params: {dish_id: 123}},
    {method: "get",    url: "/oh/no/error", headers: {break: "fast"}},
    {method: "delete", url: "/patrons/456"}
  ],
  sequential: true
}

v.s.

{
  "requests": [
    {
      "method": "POST",
      "url": "/api/v1/movies",
      "body": { }, { }
    }
  ]
}

Response

{
  results: [
    {status: 200, body: [{id: 1, name: "Jim-Bob"}, ...], headers: {}},
    {status: 201, body: {id: 4, dish_name: "Spicy Crab Legs"}, headers: {}},
    {status: 500, body: {error: {oh: "noes!"}}, headers: {Problem: "woops"}},
    {status: 200, body: null, headers: {}}}
  ]
}

v.s.

[
  {"status"=>200, "headers"=>{}, "response"=>{}},
  {"status"=>200, "headers"=>{}, "response"=>{}}
]

I believe there're some other users of batch_api would want to migrate to batch_request_api as well.

I propose two ways, and please let me know how you think:

  1. Add options to configure main keys for requests & responses (e.g. requests / results)
  2. Add an optional rack middleware to do the keys rewrite

dlackty avatar Jul 08 '18 15:07 dlackty