Send raw body in http request

1,188 views
Skip to first unread message

Brian Bravo

unread,
Aug 13, 2014, 2:58:57 PM8/13/14
to ruby-...@googlegroups.com
Hey everyone, 

What are the steps (set up) in order to send a json object in the http body request and have that identified by Grape? 

Thank you!

Daniel Doubrovkine

unread,
Aug 14, 2014, 6:51:05 AM8/14/14
to ruby-...@googlegroups.com
You don't have to do anything special other than declaring the API as JSON (or having an application/json content-type). An API with `format :json` will automatically parse POST and PUT bodies into `params`.

There's a post-json sample in https://github.com/dblock/grape-on-rack.


--
You received this message because you are subscribed to the Google Groups "Grape Framework Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-grape+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

dB. | Moscow - Geneva - Seattle - New York
code.dblock.org - @dblockdotorg - artsy.net - github/dblock

Brian Bravo

unread,
Aug 14, 2014, 11:19:52 AM8/14/14
to ruby-...@googlegroups.com
Thank you for your help! I tried the following in my app.rb file
    
    format :json
    content_type :json, "application/json"

Which resulted in "error": "The requested content-type 'text/plain' is not supported."

When I sent this in the body: {"updates":{}}

I'm using Chrome's extension Postman and sending a raw request with the content type set to application/json




--
You received this message because you are subscribed to a topic in the Google Groups "Grape Framework Discussion" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ruby-grape/j7vCwGG7kuw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ruby-grape+...@googlegroups.com.

Daniel Doubrovkine

unread,
Aug 14, 2014, 11:23:03 AM8/14/14
to ruby-...@googlegroups.com
The extension is sending data as text/plain, not application/json. That should be the content-type of the POST. 

Brian Bravo

unread,
Aug 14, 2014, 12:15:46 PM8/14/14
to ruby-...@googlegroups.com
Thanks!
Reply all
Reply to author
Forward
0 new messages