POST json body isn't set on `ctx.request.body`
See original GitHub issueWhen I POST to my endpoint with a JSON body its not showing up on the server:
{
"queries": ["pizza", "javascript"]
}
I get undefined for ctx.request.body
sending as form data seems to be ok for non-json objects. but I want to post json.
I’ve tried posting with both application/javascript
and application/json
neither work. (i’m using "koa-bodyparser": "^3.2.0"
with "koa": "^2.0.0",
)
Here is relevant app.js:
app
.use(bodyParser())
.use(cors({
methods: ['GET', 'PUT', 'POST', 'PATCH', 'DELETE']
}));
middleware(app);
routes(app);
Issue Analytics
- State:
- Created 7 years ago
- Comments:5
Top Results From Across the Web
I can't access my request.body object in Koa JS (I am using ...
To access your body object, try the following: const body = ctx.request.body;. Secondly: because in one of the comments there was a note,...
Read more >koa-body - npm
A Koa body parser middleware. Supports multipart, urlencoded and JSON request bodies.. Latest version: 6.0.1, last published: 2 months ago.
Read more >Context - Fiber
The Ctx struct represents the Context which hold the HTTP request and response. It has methods for the request query string, parameters, body,...
Read more >5.x API - Express.js
A new body object containing the parsed data is populated on the request object after the middleware (i.e. req.body ), or an empty...
Read more >koa.Request.body JavaScript and Node.js code examples
创建评论 router.post('/reply', async (ctx) => { // 通过验证器校验参数是否通过 console.log(ctx.request.body) const v = await new ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
i have meet with it too. u should set request header correctly which means ‘Content-Type’ is equal to ‘application/json’.
My fault. Didn’t define the content-type from Postman for “raw”:
https://i.imgur.com/tKyEVnA.png
The default “text” was override my manual headers.