I’m requesting rack application with
curl -X POST -d '{"device":{"username":"123456","name":"some name","location":"Hidden"}}' http://localhost:9292/device
In the rack application I’m creating request object
request = Rack::Request.new(env)
And I’m expecting that POST data will be in params hash
request.params => should be a normal hash
but somehow it’s not quite correct. I got params in this format
{{"device":{"username":"123456","name":"some name","location":"Hidden"}}=>nil}
So the params data which I needed became a key of hash. Why is that and how to make it normalhash like this
{"device":{"username":"123456","name":"some name","location":"Hidden"}}
? Thanks
normally
-dexpects data to be passed invar=valformat, and as you did not passvarit transforms your data tovarand assign a empty string to it.when you using
curllike this you get following params:then you simply parse it as json:
alternatively you can pass params like this:
then you get following params:
and simply parse into
JSON: