All Projects → creeperyang → koa-xml-body

creeperyang / koa-xml-body

Licence: MIT license
koa middleware to parse xml request body

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to koa-xml-body

Koalerplate
Simple Koa Boilerplate for APIs
Stars: ✭ 118 (+227.78%)
Mutual labels:  koa, koa2
Koa Hbs
Handlebars templates for Koa.js
Stars: ✭ 156 (+333.33%)
Mutual labels:  koa, koa2
Koa Proxies
a [email protected] proxy middleware
Stars: ✭ 125 (+247.22%)
Mutual labels:  koa, koa2
Chatroom
vue2聊天室,图灵机器人,node爬虫
Stars: ✭ 103 (+186.11%)
Mutual labels:  koa, koa2
Egg Core
A core Pluggable framework based on koa.
Stars: ✭ 194 (+438.89%)
Mutual labels:  koa, koa2
Strapi
🚀 Open source Node.js Headless CMS to easily build customisable APIs
Stars: ✭ 41,786 (+115972.22%)
Mutual labels:  koa, koa2
Vue Webpack Config
Koa2、Webpack、Vue、React、Node
Stars: ✭ 151 (+319.44%)
Mutual labels:  koa, koa2
Koach Javascript
Production ready Koa2 boilerplate.
Stars: ✭ 79 (+119.44%)
Mutual labels:  koa, koa2
Cool Admin Api
cool-admin-api 是基于egg.js、typeorm、jwt等封装的api开发脚手架、快速开发api接口
Stars: ✭ 188 (+422.22%)
Mutual labels:  koa, koa2
Blog Service
blog service @nestjs
Stars: ✭ 188 (+422.22%)
Mutual labels:  koa, koa2
Koa Mobx React Starter
A straightforward starter for Node javascript web projects. Using Koa, MobX and ReactJS (with universal / isomorphic server rendering)
Stars: ✭ 102 (+183.33%)
Mutual labels:  koa, koa2
Strapi Sdk Javascript
🔌 Official JavaScript SDK for APIs built with Strapi.
Stars: ✭ 247 (+586.11%)
Mutual labels:  koa, koa2
Koa Sslify
Enforce HTTPS in node.js koa apps
Stars: ✭ 100 (+177.78%)
Mutual labels:  koa, koa2
Postgraphile
GraphQL is a new way of communicating with your server. It eliminates the problems of over- and under-fetching, incorporates strong data types, has built-in introspection, documentation and deprecation capabilities, and is implemented in many programming languages. This all leads to gloriously low-latency user experiences, better developer experiences, and much increased productivity. Because of all this, GraphQL is typically used as a replacement for (or companion to) RESTful API services.
Stars: ✭ 10,967 (+30363.89%)
Mutual labels:  koa, koa2
Koa Ts
koa2+typescript
Stars: ✭ 82 (+127.78%)
Mutual labels:  koa, koa2
Sactive Web
🚀 A dependency injection web framework for Node.js.
Stars: ✭ 143 (+297.22%)
Mutual labels:  koa, koa2
Trafficlight
🚦 Flexible NodeJS Routing Decorators for API Routing
Stars: ✭ 69 (+91.67%)
Mutual labels:  koa, koa2
Nodejs Koa Blog
基于 Node.js Koa2 实战开发的一套完整的博客项目网站
Stars: ✭ 1,162 (+3127.78%)
Mutual labels:  koa, koa2
Github Ranking
🔍GitHub不同语言热门项目排行,Vue.js做页面展示
Stars: ✭ 160 (+344.44%)
Mutual labels:  koa, koa2
Koa Webpack Middleware
webpack dev&hot middleware for koa2
Stars: ✭ 215 (+497.22%)
Mutual labels:  koa, koa2

koa-xml-body

Build Status npm version Dependency Status 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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].