How to integrate batch requests in the Rails API?

I am creating an API with Rails 4, and I really want to create a batch request method so as not to overload my application when executing a bunch of ajax requests.

Railscasts shows how to do this in a simple way, but there are a lot of things missing.

I also tried the batch_api pearls, but I was not able to integrate it with my application.

Any ideas?

+4
source share
2 answers

Obviously, the batch_api gem does not work with rails 4, but there is a fork that was launched to upgrade it to rails 4 and ruby ​​2.0.

https://github.com/easyPEP/batch_api/tree/feature_ruby_2

0
source

, , batch_api gem Rails API (rails 5.0.0 Ruby 2.0), .

, : https://github.com/arsduo/batch_api

:

1- batch_api GemFile.

2- application.rb:

config.middleware.use BatchApi::RackMiddleware do |batch_config|
  # you can set various configuration options:
  batch_config.verb = :put # default :post
  batch_config.endpoint = "/batchapi" # default /batch
  batch_config.limit = 100 # how many operations max per request, default 50

  # default middleware stack run for each batch request
   batch_config.batch_middleware = Proc.new { }
  # default middleware stack run for each individual operation
  batch_config.operation_middleware = Proc.new { }
end

3 .

, ActionDispatch:: RequestId.

config.middleware.insert_before "ActionDispatch::RequestId", BatchApi::RackMiddleware

X-Request-ID , , ( , ).

+2

Source: https://habr.com/ru/post/1538143/


All Articles