GithubHelp home page GithubHelp logo

justm0rph3u5 / batch_request_api Goto Github PK

View Code? Open in Web Editor NEW

This project forked from netflix/batch_request_api

0.0 1.0 0.0 33 KB

Ruby Middleware to provide Batch operations on Rails applications

License: Apache License 2.0

Ruby 100.00%

batch_request_api's Introduction

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.

batch_request_api's People

Contributors

shishirmk avatar sriniwasgr avatar carsol avatar murdho avatar aspyker avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.