README.md in grape-batch-2.1.1 vs README.md in grape-batch-2.2.0

- old
+ new

@@ -98,10 +98,11 @@ ``` 'body' is optional. ### Sessions +#### Single authentication It's possible ensure a single session during the execution of the batch. You have to specify your session Proc. Before running the batch, the Proc is executed (with env as argument) and stored in rack env 'api.session' key. ```ruby # Example # Considering the config Grape::Batch.configure do |config| @@ -116,9 +117,53 @@ else # do authentication stuff end end end +``` + +#### Authentication during request batch +It is possible to either keep a token (or a session) generated by a request of the batch and pass it to the following ones. +```ruby +# Token example +# Considering this API +module Twitter + class API < Grape::API + version 'v1', using: :path + format :json + prefix 'api' + + resource :session do + get do + # route logic + header 'HTTP_X_API_TOKEN', 'my_fresh_token' + # some other logic + end + end +end + +# This route will return a token header. The header will be kept and passed to the following requests by Grape::Batch. The header will not be added to the final batch response. +``` + +```ruby +# Session example +# Considering this API +module Twitter + class API < Grape::API + version 'v1', using: :path + format :json + prefix 'api' + + resource :session do + get do + # route logic + header 'api.session', OpenStruct(id: '123456') + # some other logic + end + end +end + +# This route will return a session object. The header will be kept and passed to the following requests by Grape::Batch. The header will not be added to the final batch response. ``` ## Contributing 1. Fork it ( https://github.com/c4mprod/grape-batch/fork )