https://github.com/chrisyip/koa-buddy
Request body parser for Koa
https://github.com/chrisyip/koa-buddy
Last synced: 8 months ago
JSON representation
Request body parser for Koa
- Host: GitHub
- URL: https://github.com/chrisyip/koa-buddy
- Owner: chrisyip
- License: mit
- Created: 2014-06-26T02:48:42.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2014-09-18T10:22:45.000Z (almost 12 years ago)
- Last Synced: 2025-01-31T10:26:05.651Z (over 1 year ago)
- Language: JavaScript
- Size: 156 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# koa-buddy
[![Node version][node-image]][npm-url] [![NPM version][npm-image]][npm-url] [![Dependency Status][daviddm-image]][daviddm-url] [![Travis CI][travis-image]][travis-url]
Request body parser for Koa
# Usage
```bash
npm install --save koa-buddy
```
```js
const app = require('koa')()
, buddy = require('koa-buddy')
, router = require('koa-router')
app.use(buddy())
app.use(router(app))
/* posting application/json to /users
{
"name": "John Doe"
}
*/
app.post('/users', function* (next) {
console.log(this.request.body) // object { "name": "John Doe" }
yield next
})
/* posting application/xml to /books
Gambardella, Matthew
XML Developer's Guide
Computer
44.95
2000-10-01
An in-depth look at creating applications
with XML.
*/
app.post('/books', function* (next) {
console.log(this.request.body)
/* object:
{ declaration: { attributes: { version: '1.0' } },
root:
{ name: 'catalog',
attributes: {},
children: [ [Object] ],
content: '' } }
*/
yield next
})
```
Supported methods: `PATCH`, `POST`, `PUT`, and `TRACE`.
Supported `Content-Type`:
- `application/xml`
- `application/json`
- `application/x-www-form-urlencoded`
- `text/*` *(treated as **plain text**)*
- `multipart` *(untested)*
If `Content-Type` is not supported, `koa-buddy` passes request stream buffer to `this.request.body`.
# Todo
- examples
- tests
# Contributors
- [Chris Yip](http://github.com/chrisyip/koa-buddy/commits/master?author=chrisyip)
[node-image]: http://img.shields.io/node/v/koa-buddy.svg?style=flat-square
[npm-url]: https://npmjs.org/package/koa-buddy
[npm-image]: http://img.shields.io/npm/v/koa-buddy.svg?style=flat-square
[daviddm-url]: https://david-dm.org/chrisyip/koa-buddy
[daviddm-image]: http://img.shields.io/david/chrisyip/koa-buddy.svg?style=flat-square
[travis-url]: https://travis-ci.org/chrisyip/koa-buddy
[travis-image]: http://img.shields.io/travis/chrisyip/koa-buddy.svg?style=flat-square