# koa-wechat-xml-body

> koa middleware to parse wechat xml request body

Latest version **1.0.1** (published 2019-04-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install koa-wechat-xml-body
pnpm add koa-wechat-xml-body
yarn add koa-wechat-xml-body
bun add koa-wechat-xml-body
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2019-04-21 |
| First published | 2019-04-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 5.3 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | zss007 |
| Maintainers | zss007 |
| Keywords | xml, bodyParser, wechat, koa, xml2js, xml parser |

## Links

- npm: https://www.npmjs.com/package/koa-wechat-xml-body
- Repository: https://github.com/zss007/koa-wechat-xml-body
- Homepage: https://github.com/zss007/koa-wechat-xml-body#readme
- Issues: https://github.com/zss007/koa-wechat-xml-body/issues
- npm.io page: https://npm.io/package/koa-wechat-xml-body

## Dependencies (2)

- [xml2js](https://npm.io/package/xml2js.md) ^0.4.17
- [raw-body](https://npm.io/package/raw-body.md) ^2.2.0

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2019-04-21
- 1.0.0 — 2019-04-21

## README

# koa-wechat-xml-body

> 为 koa 解析 xml 请求

## Usage

```js
const koa = require('koa')
const xmlParser = require('koa-wechat-xml-body')

const app = koa()
app.use(xmlParser())

app.use(function(ctx, next) {
    // the parsed body will store in this.request.body
    // if nothing was parsed, body will be undefined
    ctx.body = ctx.request.body
    return next()
})
```

## Options

- **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`).
- **limit**: limit of the body. If the body ends up being larger than this limit, a 413 error code is returned. Default is `1mb`.
- **length**: length of the body. When `content-length` is found, it will be overwritten automatically.
- **onerror**: error handler. Default is a `noop` function. It means it will **eat** the error silently. You can config it to customize the response.
- **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.
- **key**: A chance to redefine what the property name to use instead of the default `body (ctx.request.body)`.

```js
app.use(xmlParser({
    limit: 128,
    encoding: 'utf8', // lib will detect it from `content-type`
    xmlOptions: {
        explicitArray: false
    },
    key: 'xmlBody', // lib will check ctx.request.xmlBody & set parsed data to it.
    onerror: (err, ctx) => {
        ctx.throw(err.status, err.message);
    }
}))
```

---
_Source: https://npm.io/package/koa-wechat-xml-body · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
