koa post get params of request code example

Example 1: how pass data from body in koa js

router.post("/api/comments", async ctx => {
  ctx.session.comments = ctx.session.comments || [];

  if (!ctx.request.body["comment"]) {
   throw Boom.badData("Empty comments not allowed");
  }

  const comment = {
   date: new Date(),
   comment: ctx.request.body["comment"],
  };
  ctx.session.comments.push(comment);
  ctx.status = 201;
  ctx.body = comment;
 });

Example 2: how pass data from body in koa js

ctx.throw(400, 'Grant: mount session middleware first')
if (ctx.method === 'POST' && !ctx.request.body) {
 ctx.throw(400, 'Grant: mount body parser middleware first')
  ctx.session.grant.override = override
 if (Object.keys(ctx.request.body || {}).length) {
  ctx.session.grant.dynamic = ctx.request.body