Skip to content

Commit

Permalink
docs: fix usage for @koa/bodyparser v5 (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
i5ting authored Jul 8, 2023
1 parent 1eb0532 commit 664cd7c
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ Parse incoming request bodies in a middleware before your handlers, available un
[![NPM](https://nodei.co/npm/@koa/bodyparser.png?downloads=true)](https://nodei.co/npm/@koa/bodyparser)

```bash
$ npm i @koa/bodyparser
$ npm i @koa/bodyparser --save
```

## Usage

```js
const Koa = require("koa");
const bodyParser = require("@koa/bodyparser");
const { bodyParser } = require("@koa/bodyparser");

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

```bash
npm install koa-bodyparser@2 --save
$ npm install koa-bodyparser@2 --save
```

#### Licences
usage

```js
const Koa = require("koa");
const bodyParser = require("@koa/bodyparser");

const app = new Koa();
app.use(bodyParser());

app.use((ctx) => {
// the parsed body will store in ctx.request.body
// if nothing was parsed, body will be an empty object {}
ctx.body = ctx.request.body;
});
```

---
## Licences

[MIT](LICENSE)

0 comments on commit 664cd7c

Please sign in to comment.