kp

koa-postparse

A middleware to parse params of POST request for koa2+

Showing:

Popularity

Downloads/wk

0

GitHub Stars

3

Maintenance

Last Commit

3yrs ago

Contributors

0

Package

Dependencies

0

License

ISC

Type Definitions

Tree-Shakeable

No?

Categories

Readme

koa-postparse

koa-postparse middleware to parse koa POST params.

用于把koa post请求传递的参数解析为String或JSON,且调用方式同get请求,如下:

  • 获取String格式参数:ctx.submitstring/ctx.request.submitstring //'name=luwuer&age=18'
  • 获取JSON格式参数:ctx.submit/ctx.request.submit //{name: 'luwuer', age: 18}

Installation

Koa-postparse requires node v8.5.4 / koa 2.0.0 or higher for (async/await) support.

NPM

Usage

const Koa = require('koa')
const postParse = require('koa-postparse')

let app = new Koa()
app.use(postParse)
app.use(async ctx => {
    if (ctx.method === 'POST') {
        // the parsed data will store in ctx.submit/ctx.request.submit 
        // just like GET (which store in ctx.query / ctx.request.query)
        ctx.body = {
            'ctx.submit': ctx.submit,
            'ctx.request.submit': ctx.request.submit,
            'ctx.submitstring': ctx.submitstring,
            'ctx.request.submitstring': ctx.request.submitstring,
        }
    }
})

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial