ParallelBatchApi
This gem is a Rack Middleware to send batch parallel request
Installation
Add this line to your application's Gemfile:
gem 'parallel_batch_api'
And then execute:
$ bundle
Or install it yourself as:
$ gem install parallel_batch_api
Usage
write this code in your config/application.rb
config.middleware.insert_before ActionDispatch::ParamsParser, ParallelBatchApi::Middleware
Request JSON example
{
"requests": [
{
"method": "GET",
"url": "/api/posts/1000"
},
{
"method": "GET",
"url": "/api/posts/2000"
},
{
"method": "GET",
"url": "/api/posts/3000",
"params": {
"page": "1"
}
}
]
}
Response
{
"responses": [
{
"status": "200",
"header": {
},
"body": {
},
"url": "/api/posts/1000",
"key": "api/posts#show"
},
{
"status": "200",
"header": {
},
"body": {
},
"url": "/api/posts/2000",
"key": "api/posts#show"
},
{
"status": "200",
"header": {
},
"body": {
},
"url": "/api/posts/3000",
"key": "api/posts#show"
}
]
}
Configuration
config/initializers/parallel_batch_api.rb
ParallelBatchApi.configure do |config|
config.batch_path = your api path default '/api/batch'
config.thread = number of thread default 1
end
Development
After checking out the repo, run bin/setup
to install dependencies. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/parallel_batch_api.
License
The gem is available as open source under the terms of the MIT License.