Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add example how to access raw body request and e.g. parse JSON from it #60

Closed
mfn opened this Issue · 1 comment

2 participants

@mfn

Hi,

in my environment I needed to process a PUT request which has a JSON payload in its body (but it's not POST request, so I can't access that payload easily).

I found the solution at http://mini.softwareas.com/posting-json-to-a-sinatra-mongodb-service in which the guy also describes that it wasn't easy to find out; especially it's not obvious that there's a request object available (it may be by skimming through the tutorial, but what I mean is that it's not explicitly told albeit still very useful).

Anyway, it boils down to that with the following code

put '/test' do
  data = JSON.parse( request.body.read.to_s )
end

Only is able to easily access it (once you find out). It would be nice to document this inside the tutorial!

thx

@rkh
Owner

Added documentation.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.