I have a very simple Ruby Rack server, like:
app = Proc.new do |env|
req = Rack::Request.new(env).params
p req.inspect
[200, { \'Content-Type\' =>
One more way to do that:
# ...
request = Rack::Request.new env
object = JSON.parse request.body.gets
# ...
See the documentation: www.rubydoc.info/gems/rack/Rack/Lint/InputWrapper
env['rack.input'].gets
This worked for me. I found that using curl or wget to test POST requests against a Rack (v1.4.1) server required using this code as a fallback to get the request body. POST requests out in the wild (e.g. GitHub WebHooks) didn't have this same problem.
It seems that I'm supposed to use something like:
msg = JSON.parse env['rack.input'].read
Then just use params
in the msg
hash.
At least it worked for me this way.