How to use the co-body.text function in co-body

To help you get started, we’ve selected a few co-body examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github t2ee / vader / test-dist / src / core / Router.js View on Github external
return yield new Promise((resolve, reject) => {
                    parse.text(koaContext).then(resolve).catch(reject);
                });
            }
github bidanjun / koa-graphql-next / src / __test__ / http-post.spec.js View on Github external
app.use(async (ctx, next) => {
        if (ctx.is('application/graphql')) {
            ctx.request.body = await bodyParser.text(ctx);
        }
        await next();
    });
github dlau / koa-body / index.js View on Github external
if (opts.json && ctx.is(jsonTypes)) {
          bodyPromise = buddy.json(ctx, {
            encoding: opts.encoding,
            limit: opts.jsonLimit,
            strict: opts.jsonStrict,
            returnRawBody: opts.includeUnparsed
          });
        } else if (opts.urlencoded && ctx.is('urlencoded')) {
          bodyPromise = buddy.form(ctx, {
            encoding: opts.encoding,
            limit: opts.formLimit,
            queryString: opts.queryString,
            returnRawBody: opts.includeUnparsed
          });
        } else if (opts.text && ctx.is('text')) {
          bodyPromise = buddy.text(ctx, {
            encoding: opts.encoding,
            limit: opts.textLimit,
            returnRawBody: opts.includeUnparsed
          });
        } else if (opts.multipart && ctx.is('multipart')) {
          bodyPromise = formy(ctx, opts.formidable);
        }
      } catch (parsingError) {
        if (typeof opts.onError === 'function') {
          opts.onError(parsingError, ctx);
        } else {
          throw parsingError;
        }
      }
    }
github adonisjs / adonis-middleware / src / BodyParser / index.js View on Github external
* _parse (request) {
    let formBody = {
      fields: {},
      files: {},
      raw: null
    }

    if (request.is(contentTypes.json)) {
      formBody.fields = yield coBody.json(request.request, this.formOptions)
    } else if (request.is(contentTypes.form)) {
      formBody.fields = yield coBody.form(request.request, this.formOptions)
    } else if (request.is(contentTypes.text)) {
      formBody.raw = yield coBody.text(request.request, this.formOptions)
    } else if (request.is(contentTypes.multipart)) {
      formBody = yield this._multipart(request, this.uploadOptions)
    }
    return formBody
  }
github dazejs / daze / packages / framework / src / request / utils / parse-body.ts View on Github external
export async function parseBody(request: any) {
  let body: any = {};
  if (request.is('json')) {
    body.fields = await buddy.json(request.req);
  } else if (request.is('urlencoded')) {
    body.fields = await buddy.form(request.req);
  } else if (request.is('text')) {
    body.fields = await buddy.text(request.req);
  } else if (request.is('multipart')) {
    body = await parseForm(request.req);
  }
  return body;
};
github polkadot-js / client / packages / client-rpc / src / index.ts View on Github external
private handlePost = async (ctx: Koa.Context): Promise => {
    const message: string = await coBody.text(ctx.req);
    const response = await this.handleMessage(message);

    ctx.type = 'application/json';
    ctx.body = JSON.stringify(response);
  }
github xiongwilee / Gracejs / middleware / body / index.js View on Github external
async function parseBody(ctx) {
    if (enableJson && ctx.request.is(jsonTypes)) {
      return await parse.json(ctx, jsonOpts);
    }
    if (enableForm && ctx.request.is(formTypes)) {
      return await parse.form(ctx, formOpts);
    }
    if (enableText && ctx.request.is(textTypes)) {
      return await parse.text(ctx, textOpts) || '';
    }

    return {};
  }
};
github t2ee / vader / dist / core / Router.js View on Github external
return yield new Promise((resolve, reject) => {
                    parse.text(koaContext).then(resolve).catch(reject);
                });
            }
github joesonw / ts-router / src / router.ts View on Github external
body = await new Promise((resolve, reject) => {
                        parse.text(context).then(resolve).catch(reject);
                    });
                } else if (matchedRoute.consume === MediaType.MULTIPART &&

co-body

request body parsing for co

MIT
Latest version published 7 months ago

Package Health Score

79 / 100
Full package analysis