{"id":13671551,"url":"https://github.com/creeperyang/koa-xml-body","last_synced_at":"2025-08-13T20:09:54.546Z","repository":{"id":57129597,"uuid":"48645436","full_name":"creeperyang/koa-xml-body","owner":"creeperyang","description":"koa middleware to parse xml request body","archived":false,"fork":false,"pushed_at":"2023-07-20T16:18:43.000Z","size":196,"stargazers_count":39,"open_issues_count":3,"forks_count":7,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-09T09:37:34.678Z","etag":null,"topics":["encoding","koa","koa-xml-body","koa2","middleware","xml-parser"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/creeperyang.png","metadata":{"files":{"readme":"readme.md","changelog":null,"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}},"created_at":"2015-12-27T13:09:49.000Z","updated_at":"2024-12-10T22:48:47.000Z","dependencies_parsed_at":"2024-01-14T17:04:35.816Z","dependency_job_id":"5062860d-120a-47e6-80c3-c62d3271b824","html_url":"https://github.com/creeperyang/koa-xml-body","commit_stats":{"total_commits":43,"total_committers":4,"mean_commits":10.75,"dds":"0.13953488372093026","last_synced_commit":"816e167c8eb8689059dc7ba6fd63404831e778a7"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/creeperyang/koa-xml-body","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creeperyang%2Fkoa-xml-body","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creeperyang%2Fkoa-xml-body/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creeperyang%2Fkoa-xml-body/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creeperyang%2Fkoa-xml-body/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/creeperyang","download_url":"https://codeload.github.com/creeperyang/koa-xml-body/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creeperyang%2Fkoa-xml-body/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269734149,"owners_count":24466554,"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","status":"online","status_checked_at":"2025-08-10T02:00:08.965Z","response_time":71,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["encoding","koa","koa-xml-body","koa2","middleware","xml-parser"],"created_at":"2024-08-02T09:01:12.719Z","updated_at":"2025-08-13T20:09:54.512Z","avatar_url":"https://github.com/creeperyang.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","仓库"],"sub_categories":["中间件"],"readme":"# koa-xml-body\n\n[![test](https://github.com/creeperyang/koa-xml-body/actions/workflows/ci.yml/badge.svg)](https://github.com/creeperyang/koa-xml-body/actions/workflows/ci.yml)\n[![npm version](https://badge.fury.io/js/koa-xml-body.svg)](https://badge.fury.io/js/koa-xml-body)\n[![download times](https://img.shields.io/npm/dm/koa-xml-body.svg)](https://www.npmjs.com/package/koa-xml-body)\n[![download times](https://img.shields.io/npm/dt/koa-xml-body.svg)](https://www.npmjs.com/package/koa-xml-body)\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fcreeperyang%2Fkoa-xml-body.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fcreeperyang%2Fkoa-xml-body?ref=badge_shield)\n\n\u003e Parse xml request body for Koa\n\n## Install\n\n[![NPM](https://nodei.co/npm/koa-xml-body.png?downloads=true\u0026downloadRank=true\u0026stars=true)](https://nodei.co/npm/koa-xml-body/)\n\n## Usage\n\n```js\nconst koa = require('koa')\nconst xmlParser = require('koa-xml-body')\n\nconst app = koa()\napp.use(xmlParser())\n\napp.use(function(ctx, next) {\n    // the parsed body will store in this.request.body\n    // if nothing was parsed, body will be undefined\n    ctx.body = ctx.request.body\n    return next()\n})\n```\n\n`koa-xml-body` will carefully check and set `context.request.body`, so it can **intergate** well with other body parsers such as `koa-bodyparser`:\n\n```js\n// ...\nconst bodyParser = require('koa-bodyparser')\n\n// ...\napp.use(xmlParser())\napp.use(bodyParser())\n```\n\n**Note:**\n\n- For `koa@2.x`, use version `2.x` or `3.x`;\n- For `koa@1.x`, use `koa-xml-body@1.x`.\n\n## Options\n\n- **encoding**: requested encoding. Default is `utf8`. If not set, the lib will retrive it from `content-type`(such as `content-type:application/xml;charset=gb2312`).\n- **limit**: limit of the body. If the body ends up being larger than this limit, a 413 error code is returned. Default is `1mb`.\n- **length**: length of the body. When `content-length` is found, it will be overwritten automatically.\n- **onerror**: error handler. Default is a `None`. It means it will **throws** the error. You can config it to customize the response.\n- **xmlOptions**: options which will be used to parse xml. Default is `{}`. See [`xml2js Options`](https://github.com/Leonidas-from-XIV/node-xml2js#options) for details.\n- **key**: A chance to redefine what the property name to use instead of the default `body (ctx.request.body)`.\n\n```js\napp.use(xmlParser({\n    limit: 128,\n    encoding: 'utf8', // lib will detect it from `content-type`\n    xmlOptions: {\n        explicitArray: false\n    },\n    key: 'xmlBody', // lib will check ctx.request.xmlBody \u0026 set parsed data to it.\n    onerror: (err, ctx) =\u003e {\n        console.error(err);\n        ctx.throw(err.status, err.message);\n    }\n}))\n```\n\n## Licences\n\n[MIT](LICENSE)\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fcreeperyang%2Fkoa-xml-body.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fcreeperyang%2Fkoa-xml-body?ref=badge_large)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcreeperyang%2Fkoa-xml-body","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcreeperyang%2Fkoa-xml-body","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcreeperyang%2Fkoa-xml-body/lists"}