Skip to content

Migrating from arsduo/batch_api #13

Description

@dlackty

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions