Accessing JSON Request Parameters in Sails
In my controllers and other scopes where there is an object req
, I can access the request parameters with req.params('username')
. This is fine for normal POST data, but I want my API to accept a JSON object in the request body and convert it to parameters that I can still get with req.params()
.
So, for example, if I send this as a POST request body to my controller action:
{'username': 'Chris', 'password': 'mypass'}
I want to get username and password using req.params('username')
and req.param('password')
.
At the moment, the only thing that works is to send data like this:
username=Chris&password=mypass
Any ideas?
source to share
You can get it from req.body
. See http://sailsjs.org/#/documentation/reference/req/req.body.html
source to share