# @curveball/bodyparser

> A curveball middleware for parsing JSON and Text bodies.

Latest version **1.0.0** (published 2024-01-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install @curveball/bodyparser
pnpm add @curveball/bodyparser
yarn add @curveball/bodyparser
bun add @curveball/bodyparser
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2024-01-15 |
| First published | 2018-06-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM |
| Node | >= 18 |
| Dependencies | 0 |
| Unpacked size | 7.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Evert Pot |
| Maintainers | evrt, mihok, juhangsin, beckypollard |
| Keywords | http, framework, nodejs, typescript, http2, curveball, json, urlencoded, form-data, middleware |

## Links

- npm: https://www.npmjs.com/package/@curveball/bodyparser
- Repository: https://github.com/curveball/bodyparser
- Homepage: https://github.com/curveball/bodyparser#readme
- Issues: https://github.com/curveball/bodyparser/issues
- npm.io page: https://npm.io/package/@curveball/bodyparser

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.0.0 (latest) — 2024-01-15
- 0.6.1 — 2023-02-14
- 0.6.0 — 2023-02-14
- 0.5.0 — 2022-09-03
- 0.4.14 — 2021-02-19
- 0.4.13 — 2021-02-19
- 0.4.12 — 2021-02-19
- 0.4.11 — 2021-02-19
- 0.4.10 — 2021-02-19
- 0.4.9 — 2021-02-19
- 0.4.8 — 2021-02-19
- 0.4.7 — 2021-02-19
- 0.4.6 — 2020-02-05
- 0.4.5 — 2020-01-28
- 0.4.4 — 2020-01-06
- … 11 more at https://npm.io/package/@curveball/bodyparser/versions

## README

Curveball Body Parser
=====================

This package is a middleware for [Curveball][1]. It helps parsing JSON and
Text request bodies.

When this middleware is added, it will automatically read all bodies from
requests that have the following values as their `Content-Type` header:

* `application/json`
* `application/*+json`
* `application/x-www-form-urlencoded`
* `text/*`

It sets the result of this parsing process to the `context.request.body`
property. In the case of text bodies, it will result in a string.

In the case of JSON bodies, it will be the result of `JSON.parse` on the
body.

Installation
------------

    npm install @curveball/bodyparser


Getting started
---------------

```typescript
import { Application } from '@curveball/core';
import bodyParser from '@curveball/bodyparser';

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


app.use( ctx => {
  // Log request bodies
  console.log(ctx.request.body);
});
```

API
---

### bodyParser

The default export for this package is the `bodyParser` function. When called,
this function returns a middleware.

[1]: https://github.com/curveball/core

---
_Source: https://npm.io/package/@curveball/bodyparser · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
