I am unable to make a POST method request with . I am unable to send a request object with it.
For example see this example. Here only GET request is being made. But I want to make a POST request.
I am unable to make a POST method request with . I am unable to send a request object with it.
For example see this example. Here only GET request is being made. But I want to make a POST request.
I was facing the same issue. When I tried to make a POST request I was receiving undefined
as the value of the body
object.
I ended up not using koa-http-request
as the example provided in your link. I have used both koa-bodyparser
and koa-router
middlewares instead:
const Koa = require('koa');
const KoaRouter = require('koa-router');
const bodyParser = require('koa-bodyparser');
const app = new Koa();
const router = new KoaRouter();
// ===== M i d d l e w a r e s =====
// Body parser
app.use(bodyParser());
// Router
app.use(router.routes()).use(router.allowedMethods());
// ...
const addItem = async (context) => {
const body = await context.request.body;
// Now you can access the body object
console.log(body)
}
// ...
router.post('/', addItem);
In my case it had worked as it supposed to. :)