Does anybody know why req.body is empty in my custom express route?
I'm doing a get request to /test. The request is being received correctly, but when I try to extract parameters from the Body, I get nothing
are you sending anything in the body?
Yes, I'm sending a json in the body. And the response is being received. I set that route in server.ts
do you have an
app.use(express.json());
somewhere in your server.ts?
i would also try changing it to
app.post
to receive a
req.body
personally my get routes usually use URL/query params as opposed to a req body
That worked!! Thanks 😄
nice one!
The app.use(express.json()); worked.
And about the post, you are right, that is a better practice. This was just a test. In the real function code I'm using a post request. Thanks! 😄
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.