{"id":14989462,"url":"https://github.com/hkust-vislab/koa-bodyparser-ts","last_synced_at":"2026-02-27T13:03:57.117Z","repository":{"id":73520725,"uuid":"90466310","full_name":"HKUST-VISLab/koa-bodyparser-ts","owner":"HKUST-VISLab","description":"a koa-bodyparser in typescript","archived":false,"fork":false,"pushed_at":"2020-06-02T00:04:27.000Z","size":4353,"stargazers_count":7,"open_issues_count":11,"forks_count":0,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-12T01:16:15.556Z","etag":null,"topics":["body-parser","bodyparser","koa2","koajs","middleware","typescript"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/HKUST-VISLab.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-05-06T13:52:43.000Z","updated_at":"2022-07-18T20:28:16.000Z","dependencies_parsed_at":"2023-09-15T18:01:48.678Z","dependency_job_id":null,"html_url":"https://github.com/HKUST-VISLab/koa-bodyparser-ts","commit_stats":{"total_commits":65,"total_committers":3,"mean_commits":"21.666666666666668","dds":0.5384615384615384,"last_synced_commit":"ca10742c4d9903e2d1db6c770dffec42f96854f4"},"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HKUST-VISLab%2Fkoa-bodyparser-ts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HKUST-VISLab%2Fkoa-bodyparser-ts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HKUST-VISLab%2Fkoa-bodyparser-ts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HKUST-VISLab%2Fkoa-bodyparser-ts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HKUST-VISLab","download_url":"https://codeload.github.com/HKUST-VISLab/koa-bodyparser-ts/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248501858,"owners_count":21114684,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["body-parser","bodyparser","koa2","koajs","middleware","typescript"],"created_at":"2024-09-24T14:18:24.648Z","updated_at":"2026-02-27T13:03:57.071Z","avatar_url":"https://github.com/HKUST-VISLab.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"koa-bodyparser-ts\n=================\n\n[![Build Status](https://travis-ci.org/HKUST-VISLab/koa-bodyparser-ts.svg?branch=master)](https://travis-ci.org/HKUST-VISLab/koa-bodyparser-ts)\n[![npm version](https://badge.fury.io/js/koa-bodyparser-ts.svg)](https://badge.fury.io/js/koa-bodyparser-ts)\n[![codecov](https://codecov.io/gh/HKUST-VISLab/koa-bodyparser-ts/branch/master/graph/badge.svg)](https://codecov.io/gh/HKUST-VISLab/koa-bodyparser-ts)\n[![David](https://david-dm.org/HKUST-VISLab/koa-bodyparser-ts/status.svg)](https://github.com/HKUST-VISLab/koa-bodyparser-ts)\n[![Greenkeeper badge](https://badges.greenkeeper.io/HKUST-VISLab/koa-bodyparser-ts.svg)](https://greenkeeper.io/)\n\n\nA body parser for koa, base on [co-body](https://github.com/tj/co-body). support `json`, `form` and `text` type body.\n\n## Install\n\n`npm install koa-bodyparser-ts --save`\n\n## Usage\n\n```ts\n\nimport * as Koa from \"koa\";\nimport bodyParser from \"koa-bodyparser-ts\";\n\nconst app = new Koa();\napp.use(bodyParser());\n\napp.use(async ctx =\u003e {\n  // the parsed body will store in ctx.request.body\n  // if nothing was parsed, body will be an empty object {}\n  ctx.body = ctx.request.body;\n});\n```\n\n## Options\n\n* **enableTypes**: parser will only parse when request type hits enableTypes, default is `['json', 'form']`.\n* **encode**: requested encoding. Default is `utf-8` by `co-body`.\n* **formLimit**: limit of the `urlencoded` body. If the body ends up being larger than this limit, a 413 error code is returned. Default is `56kb`.\n* **jsonLimit**: limit of the `json` body. Default is `1mb`.\n* **textLimit**: limit of the `text` body. Default is `1mb`.\n* **strict**: when set to true, JSON parser will only accept arrays and objects. Default is `true`. See [strict mode](https://github.com/cojs/co-body#options) in `co-body`. In strict mode, `ctx.request.body` will always be an object(or array), this avoid lots of type judging. But text body will always return string type.\n* **detectJSON**: custom json request detect function. Default is `null`.\n\n  ```js\n  app.use(bodyparser({\n    detectJSON: function (ctx) {\n      return /\\.json$/i.test(ctx.path);\n    }\n  }));\n  ```\n\n* **extendTypes**: support extend types:\n\n  ```js\n  app.use(bodyparser({\n    extendTypes: {\n      json: ['application/x-javascript'] // will parse application/x-javascript type body as a JSON string\n    }\n  }));\n  ```\n\n* **onerror**: support custom error handle, if `koa-bodyparser` throw an error, you can customize the response like:\n\n  ```js\n  app.use(bodyparser({\n    onerror: function (err, ctx) {\n      ctx.throw('body parse error', 422);\n    }\n  }));\n  ```\n\n* **disableBodyParser**: you can dynamic disable body parser by set `ctx.disableBodyParser = true`.\n\n```js\napp.use(async (ctx, next) =\u003e {\n  if (ctx.path === '/disable') ctx.disableBodyParser = true;\n  await next();\n});\napp.use(bodyparser());\n```\n\n## Raw Body\n\nYou can access raw request body by `ctx.request.rawBody` after `koa-bodyparser` when:\n\n1. `koa-bodyparser` parsed the request body.\n2. `ctx.request.rawBody` is not present before `koa-bodyparser`.\n\n## Licences\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhkust-vislab%2Fkoa-bodyparser-ts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhkust-vislab%2Fkoa-bodyparser-ts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhkust-vislab%2Fkoa-bodyparser-ts/lists"}