#req.body in POST endpoint is undefined
16 messages · Page 1 of 1 (latest)
In another project, not related to medusa, I remember something related to bodyparser middleware but don't remember if it's in this case or not
https://github.com/nazimboudeffa/nem-rest-api-auth-simple/blob/main/app.js
I am really not sure
Rewriting an API interest me, do you have a GitHub repo to test what you are coding ?
ohhhh thank bro so much, I thought that medusa intergated bodypaser defaultly for us
I am not yet at this level of the knowledge but we can check it together 😄
☮️ ❤️
@pliant tinsel i am struggling with this same thing. how did you solve it?
You need to use bodyParser middleware, as shown in Naz's link above.
unfortunately that isn't working for me
import express, { Router } from "express";
export default (rootDirectory: string, pluginOptions: any) => {
const router = Router()
router.use(express.json())
router.use(bodyParser.json())
router.post("/hello", (req, res) => {
console.debug(req.body)
res.json({"hello":"world"})
});
return router
};```
I am getting an empty body
uh. 🙂 nm
it is working
just ftr - don't need to use bodyParser. Just express.json() is enough