'Post request from postman seems to not be sending any json data
I am trying to test my project out, and I am using postman right now to pass in some data: I have set postman to "POST" to my local server through "body", and then I send the following:
{
"name": "My Name"
}
Then, my server file post request is:
const express = require('express'),
router = express.Router(),
gravatar = require('gravatar'),
bcrypt = require('bcryptjs'),
{check, validationResult} = require('express-validator');
// User Model
const User = require('../../models/User');
// @route GET api/users
// @description Test Route
// @access Public
router.get('/', (req, res) => {
res.send("User Route")
});
// @route POST api/users
// @description Register User
// @access Public
router.post('/', [
check('name', 'Name is required').not().isEmpty(),
check('email', 'Please enter a valid email address').isEmail(),
check('password', 'Password must contain at least 6 characters').isLength({min: 6})
], async (req, res) => {
return res.send(req.body);
});
module.exports = router;
I put in the res.send(req.body) to confirm anything is being sent to my server in general before I test any of the other code out, however, the res.send only returns: {} meaning that no json information has been sent to my server. I know that the routes work because when I put in a GET request, it acts as expected. Is there something obvious I am missing here? Thank you.
Solution 1:[1]
I have figured out the answer to my issue. In the "Headers" I was missing the "Content-type - application/json". After adding this is seems to work.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Zernst |


