Difference between req.query and req.body
Reference: stack overflow anser
req.query contains the query params of the request.
For example in sample.com?foo=bar
, req.query
would be {foo:"bar"}
req.body contains anything in the request body. Typically this is used on PUT
and POST
requests.
For example a POST
to sample.com with the body of {"foo":"bar"}
and a header of type application/json
, req.body
would contain {foo: "bar"}
Or we can just remember this: query
for GET, body
for POST and PUT.