Params empty when Angular does JSON POST requests

192 views
Skip to first unread message

John Henderson

unread,
May 4, 2013, 9:59:00 AM5/4/13
to ruby-...@googlegroups.com
Hello,

I have an Angular frontend sending data (via JSON POST) to an Grape endpoint. The params are empty though. How come?

I did manage to get the params data using env['action_dispatch.request.request_parameters'], but this doesn't seem right. Am I wrong?

Reading the docs and past issues I'm certain the params Hasie Mash object should have the data posted via json but can't figure why it's not getting populated.

Any ideas?

Thanks
John

Adam Williams

unread,
May 4, 2013, 10:12:27 AM5/4/13
to ruby-...@googlegroups.com
John,

If you have your API format set as :json, then you will find the request body parsed into env['api.request.body']. This is not part of params. Rails and some other frameworks will take application/json bodies and put them into the params as _json, but Grape does not do this. I'm not sure it should, either.

HTH, Adam


--
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/groups/opt_out.
 
 

John Henderson

unread,
May 4, 2013, 3:11:09 PM5/4/13
to ruby-...@googlegroups.com
Hi Adam,

I get what you're saying. However, env['api.request.body'] returns nil. Looks like env['api.request.body'] doesn't seem to exist as a key in the env hash.

I'm happy to use env['action_dispatch.request.request_parameters'] anyway.

Many thanks,
John

Daniel Doubrovkine

unread,
May 5, 2013, 2:05:13 PM5/5/13
to ruby-...@googlegroups.com
You should build a repro for this and, possibly, file a bug. The params should not be empty assuming you specify the correct content-type and your API supports it (via content-type declarations). JSON is on by default, so this should "just work".

Daniel Doubrovkine

unread,
May 30, 2013, 7:49:12 AM5/30/13
to ruby-...@googlegroups.com
This just came up on the list again. Did you ever fix your issue? Thanks.

code.dblock.org - @dblockdotorg - artsy.net - github/dblock

André Dieb

unread,
May 30, 2013, 8:02:49 AM5/30/13
to ruby-...@googlegroups.com
Daniel,

You just reminded of a probable fix I did on my end.

John:

I remember that the params were getting parsed and consumed before reaching Grape. IIRC it was ActionDispatch::ParamsParser. If this is the case, this can be attempted to avoid it pre-parsing your parameters when under rails.
André Dieb Martins
Reply all
Reply to author
Forward
0 new messages