Async endpoints for Grape APIs
Enable asyncronous endpoints to avoid blocking slow requests within EventMachine or Threads.
This can be used with any Ruby server supporting env['async.callback'] or
env['rack.hijack'] (the Rack Hijack API).
Installation
Add this line to your application's Gemfile:
gem 'grape', '>= 0.14.0'
gem 'grape-async'
Usage
class API < Grape::API
use Grape::Async
async
get do
# code to run asyncronously ...
end
end
The async directive accepts either :em for EventMachine based async or :threaded for thread based async.
The default is :threaded.
Contributing
- Fork it ( https://github.com/stuart/grape-async/fork )
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request