How to get POST params?
See original GitHub issuekoa: v2.0.0 koa-router: v7.0.1
// user
router
.get('/user/:id', async (ctx, next) => {
let user = await User.query();
ctx.body = user;
})
.post('/user/', async (ctx, next) => {
ctx.body = ctx.req;
})
Everything seems all right, but I can’t find the post params.
Insert the code:
router
.get('/user/:id', async (ctx, next) => {
let user = await User.query();
ctx.body = user;
})
.post('/user/', async (ctx, next) => {
var data = '';
ctx.on('data', function (chunk) {
data += chunk;
})
ctx.on('end', function (chunk) {
console.log(data);
})
ctx.body = ctx.req;
})
The data
will be print correctly!
I don’t want to use this approach.
Have any good Suggestions?
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (1 by maintainers)
Top Results From Across the Web
How are parameters sent in an HTTP POST request?
Short answer: in POST requests, values are sent in the "body" of the request. With web- ...
Read more >How To Retrieve URL and POST Parameters with Express
First, open your terminal window and create a new project directory: mkdir express-params-example. … Step 2 – Using req. query with URL ...
Read more >Get / Post Parameters - Dotcom-Monitor
Name: Specify the name of the parameter as it will appear in the request. Value: Enter the value associated with the name of...
Read more >How to retrieve the POST query parameters using Express
Retrieve the POST query parameters using Express ... POST query parameters are sent by HTTP clients for example by forms, or when performing...
Read more >How to Send GET and POST Requests with JavaScript Fetch ...
Creating get and post Functions ... // All logic is here. };const get = ( url, params ) => request( url, params, 'GET'...
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
@xunjianxiang you can get your POST params like this:
@hanxu317317 you need a body parser. Google for koa-bodyparser and/or koa-body.