Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

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

Closed
mfn opened this Issue Sep 14, 2010 · 1 comment

Comments

Projects
None yet
2 participants

mfn commented Sep 14, 2010

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

Owner

rkh commented Oct 11, 2010

Added documentation.

@7stud 7stud pushed a commit to 7stud/sinatra that referenced this issue Aug 27, 2014

@rkh rkh Merge pull request #60 from neilparikh/patch-1
Fix error in contrib/index.markdown
5491159

This issue was closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment