Axios post request.body is empty object
You are missing one middleware, bodyParser.json()
. Add it to your configuration.
mongoose.connect("mongodb://localhost/blog-react");app.set("view engine", "ejs");app.use(express.static("public"));app.use(bodyParser.json()); // <--- Hereapp.use(bodyParser.urlencoded({extended: true}));
It looks like you only have two points left to make it work :
one : the http method should be set to POST instead of GET since you want to send something.
two : you can then add the http header (like what you did with the authorization header) Content-Type: 'application/json`
On the back-end don't forget to use some kind of body parser utility package like this one : body-parser and set it up with your app.
I suppose your server is using express, here is how you will do it with express :
const express = require('express');const app = express();const bodyParser = require('body-parser')const jsonParser = bodyParser.json();app.use(jsonParser); // use it globallyapp.get('your_route', jsonParser, otherMiddleware, (req, res) => ...); // use it for specific routes/* ... rest of your code */