No release in over 3 years
Low commit activity in last 3 years
There's a lot of open issues
Batch API middleware.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 1.7
~> 10.0

Runtime

>= 4.0
 Project Readme

batch_request_api

NetflixOSS Lifecycle

Rails middleware gem to achieve Batch creates, updates and deletes.

  • Customizable middleware
  • Batch create, update and delete records sequentially or in parallel

Installation

Add this line to your application's Gemfile:

gem 'batch_request_api'

Or install it yourself as:

  $ gem install batch_request_api

Overview

After installing the gem, you get the middleware which will intercept requests to the following urls.

  • batch_sequential (/api/v1/batch_sequential)
  • batch_parallel (/api/v1/batch_parallel)

To use custom URLs, add a configuration block to your app initialization. Example:

BatchRequestApi.configure do |config|
  config.batch_sequential_paths = ['/api/v1/batch_sequential']
  config.batch_parallel_paths = ['/api/v1/batch_parallel']
end

API endpoint can be disabled by setting the path to a falsy value (nil/false).

Sequential Usage

This is the simplest way to implement batch. One network request to /api/v1/batch_sequential containing the batched payload will work with a regular rails controller.

Parallel Usage

This requires your controller to iterate and apply a transaction. One network request to /api/v1/batch_parallel containing the batched payload will need a code similar to this sample.

The batch request payload is available on the controller using params['json']

Batch Client

We expect that you will probably use the Ember Add on with this gem to make the batch request and receive a response.

If not, no worries we have built a sample Ruby Client for that reason.

Here are the sample payloads that the middleware expects for create/update/delete. The ruby client constructs the format for create action.

Batch Request Payload:

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

Batch Request Response:

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

Contributing

If you would like to contribute, you can fork the project, edit, and make a pull request.