https://github.com/curveball/bodyparser
A middleware to parse JSON and Text bodies.
https://github.com/curveball/bodyparser
curveball framework hacktoberfest http http2 middleware nodejs push typescript
Last synced: 5 months ago
JSON representation
A middleware to parse JSON and Text bodies.
- Host: GitHub
- URL: https://github.com/curveball/bodyparser
- Owner: curveball
- License: mit
- Created: 2018-06-30T03:22:10.000Z (over 7 years ago)
- Default Branch: main
- Last Pushed: 2024-01-15T02:07:23.000Z (about 2 years ago)
- Last Synced: 2025-08-17T23:42:35.774Z (6 months ago)
- Topics: curveball, framework, hacktoberfest, http, http2, middleware, nodejs, push, typescript
- Language: TypeScript
- Homepage:
- Size: 928 KB
- Stars: 5
- Watchers: 10
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: changelog.md
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
Awesome Lists containing this project
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