homebridge-config-ui-x
Version:
A web based management, configuration and control platform for Homebridge
65 lines (46 loc) • 2.03 kB
Markdown
# fastify-formbody
[](https://www.npmjs.com/package/fastify-formbody)
[](https://www.npmjs.com/package/fastify-formbody)
[](https://travis-ci.org/fastify/fastify-formbody)
[](https://standardjs.com)
[](https://codecov.io/gh/fastify/fastify-formbody)
[](https://snyk.io/test/github/fastify/fastify-formbody)
[](https://greenkeeper.io/)
A simple plugin for [Fastify][fastify] that adds a content type parser for
the content type `application/x-www-form-urlencoded`.
[fastify]: https://www.fastify.io/
## Example
Given the following code:
```js
const fastify = require('fastify')()
fastify.register(require('fastify-formbody'))
fastify.post('/', (req, reply) => {
reply.send(req.body)
})
fastify.listen(8000, (err) => {
if (err) throw err
})
```
And a `POST` body of:
```html
foo=foo&bar=bar&answer=42
```
The sent reply would be the object:
```js
{
foo: 'foo',
bar: 'bar',
answer: 42
}
```
## Options
The plugin accepts an options object with the following properties:
+ `bodyLimit`: the maximum amount of bytes to process
before returning an error. If the limit is exceeded, a `500` error will be
returned immediately. When set to `undefined` the limit will be set to whatever
is configured on the parent Fastify instance. The default value is
whatever is configured in
[fastify](https://github.com/fastify/fastify/blob/master/docs/Factory.md#bodylimit)
(`1048576` by default).
## License
Licensed under [MIT](./LICENSE)