6.1.0 • Published 4 years ago

co-body v6.1.0

Weekly downloads
576,765
License
MIT
Repository
github
Last release
4 years ago

co-body

NPM version build status Test coverage David deps npm download

Parse request bodies with generators inspired by Raynos/body.

Installation

$ npm install co-body

Options

  • limit number or string representing the request size limit (1mb for json and 56kb for form-urlencoded)
  • strict when set to true, JSON parser will only accept arrays and objects; when false will accept anything JSON.parse accepts. Defaults to true. (also strict mode will always return object).
  • queryString an object of options when parsing query strings and form data. See qs for more information.
  • returnRawBody when set to true, the return value of co-body will be an object with two properties: { parsed: /* parsed value */, raw: /* raw body */}.
  • jsonTypes is used to determine what media type co-body will parse as json, this option is passed directly to the type-is library.
  • formTypes is used to determine what media type co-body will parse as form, this option is passed directly to the type-is library.
  • textTypes is used to determine what media type co-body will parse as text, this option is passed directly to the type-is library.

more options available via raw-body:

Example

// application/json
var body = await parse.json(req);

// explicit limit
var body = await parse.json(req, { limit: '10kb' });

// application/x-www-form-urlencoded
var body = await parse.form(req);

// text/plain
var body = await parse.text(req);

// either
var body = await parse(req);

// custom type
var body = await parse(req, { textTypes: ['text', 'html'] });

Koa

This lib also supports ctx.req in Koa (or other libraries), so that you may simply use this instead of this.req.

// application/json
var body = await parse.json(this);

// application/x-www-form-urlencoded
var body = await parse.form(this);

// text/plain
var body = await parse.text(this);

// either
var body = await parse(this);

License

MIT

complyrubbish.magong.ioco-permitbentojs-apimojaloop-fxp-scheme-adapter@rappopo/cuk-utilsmart-api-booking-service@brielov/metal@pinstripe/core@easyboot/coresa-appkoa2-api-proxysa-servertrpc-openapi-klapacz@everything-registry/sub-chunk-1345@compas/serverbookdownbonobrisk-controllercss-em-gridts-routertrpc-openapitrpc-openapi-fetchtrpc-openapi-fork-fastify-pr-177trpc-swaggerts-brpcuserjsuniversal-log-serverutopia-server@dikac/koa-bodysyncable-apivite-plugin-mock-dev-servervite-plugin-ssr-render@dwing/koa-joi-routerwaigovukoa-bodyparsepatchvz-dockerinovbox-robotverascli@ecubelabs/koa-joi-router@easegram/frameworkvtexvtex2vtex-graphql-builder@ennis/apiui5-local-neodatabridge-logger@fisch0920/trpc-openapiweb-routeweb-test-runnertraining-koacozumeltora@dasha.ai/platform-sdk@dasha.ai/sdksuch-cli@daidaviddavies/daitimestreamsoftco-production@danbre14/temp-trpc-openapisugar-servertashfincircecirce-body-parserciscospark-webhook-validatorcisco-webex-toolsclannad@dazejs/frameworkcontrol-freakcontrol-freak-miimetiqtidyjscottage-barneycortex-search-serveref-video-tube@koa-better-modules/joi-router@koa/bodyparseregg-github-webhookegg-gitlab-webhookegg-proxy-middleware@gatewayjs/gatewaywisecore@gyrfalcon/http@halsp/bodyxg-command-loon@macchiatojs/body@koex/body@mojaloop/sdk-scheme-adapter@notevenaneko/trpc-openapi@lvchengbin/koa-bridge@nook/koa-joi-routeremq-service@dta5/koa-joi-routerdpmui-tool@irv/auth-middleware-public@jianxcao/mock@janzal/koa-joi-routerykoa@highoutput/email-auth@highoutput/supportxnv-sqlwjxday-5
6.1.0

4 years ago

6.0.0

6 years ago

5.2.0

6 years ago

5.1.1

7 years ago

5.1.0

7 years ago

5.0.3

7 years ago

5.0.2

7 years ago

5.0.1

7 years ago

5.0.0

7 years ago

4.2.0

8 years ago

4.1.0

8 years ago

4.0.0

9 years ago

3.1.0

9 years ago

3.0.0

9 years ago

2.0.0

9 years ago

1.2.0

9 years ago

1.1.0

9 years ago

1.0.0

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago