<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          koa-xml-bodykoa middleware to parse xml request body

          聯(lián)合創(chuàng)作 · 2023-09-21 14:21

          koa-xml-body

          npm version download times FOSSA Status

          Parse xml request body for Koa

          Install

          NPM

          Usage

          const koa = require('koa')
          const xmlParser = require('koa-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()
          })

          koa-xml-body will carefully check and set context.request.body, so it can intergate well with other body parsers such as koa-bodyparser:

          // ...
          const bodyParser = require('koa-bodyparser')
          
          // ...
          app.use(xmlParser())
          app.use(bodyParser())

          Note:

          Current version (v2.x) of koa-xml-body is writtern with ES2015 and for koa@2. If you use [email protected], use [email protected] instead.

          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 for details.
          • key: A chance to redefine what the property name to use instead of the default body (ctx.request.body).
          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);
              }
          }))

          Licences

          MIT

          FOSSA Status

          瀏覽 4
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          編輯 分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          編輯 分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  99久久精品免费看 | 久久久久久 豆花视频 | 成人一级自拍网站 | 美女自慰网站免费看 | 午夜精品久久久久久久99黑人 |