Skip to content

Commit 664cd7c

Browse files
authored
docs: fix usage for @koa/bodyparser v5 (#154)
1 parent 1eb0532 commit 664cd7c

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

README.md

+19-5
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ Parse incoming request bodies in a middleware before your handlers, available un
2424
[![NPM](https://nodei.co/npm/@koa/bodyparser.png?downloads=true)](https://nodei.co/npm/@koa/bodyparser)
2525

2626
```bash
27-
$ npm i @koa/bodyparser
27+
$ npm i @koa/bodyparser --save
2828
```
2929

3030
## Usage
3131

3232
```js
3333
const Koa = require("koa");
34-
const bodyParser = require("@koa/bodyparser");
34+
const { bodyParser } = require("@koa/bodyparser");
3535

3636
const app = new Koa();
3737
app.use(bodyParser());
@@ -116,11 +116,25 @@ You can access raw request body by `ctx.request.rawBody` after `koa-bodyparser`
116116
To use `koa-bodyparser` with [email protected], please use [bodyparser 2.x](https://github.com/koajs/bodyparser/tree/2.x).
117117

118118
```bash
119-
npm install koa-bodyparser@2 --save
119+
$ npm install koa-bodyparser@2 --save
120120
```
121121

122-
#### Licences
122+
usage
123+
124+
```js
125+
const Koa = require("koa");
126+
const bodyParser = require("@koa/bodyparser");
127+
128+
const app = new Koa();
129+
app.use(bodyParser());
130+
131+
app.use((ctx) => {
132+
// the parsed body will store in ctx.request.body
133+
// if nothing was parsed, body will be an empty object {}
134+
ctx.body = ctx.request.body;
135+
});
136+
```
123137

124-
---
138+
## Licences
125139

126140
[MIT](LICENSE)

0 commit comments

Comments
 (0)