{"id":22327317,"url":"https://github.com/unematiii/fastify-simple-form","last_synced_at":"2026-05-04T06:33:38.115Z","repository":{"id":56386668,"uuid":"311328314","full_name":"unematiii/fastify-simple-form","owner":"unematiii","description":"Fastify plugin that adds content type parser for the application/x-www-form-urlencoded and/or multipart/form-data types","archived":false,"fork":false,"pushed_at":"2022-07-13T13:41:17.000Z","size":330,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-31T07:45:22.522Z","etag":null,"topics":["fastify","fastify-plugin","forms","multipart","urlencoded"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/unematiii.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-11-09T12:16:30.000Z","updated_at":"2022-07-13T13:41:21.000Z","dependencies_parsed_at":"2022-08-15T17:50:19.296Z","dependency_job_id":null,"html_url":"https://github.com/unematiii/fastify-simple-form","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unematiii%2Ffastify-simple-form","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unematiii%2Ffastify-simple-form/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unematiii%2Ffastify-simple-form/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unematiii%2Ffastify-simple-form/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/unematiii","download_url":"https://codeload.github.com/unematiii/fastify-simple-form/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245599441,"owners_count":20642103,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fastify","fastify-plugin","forms","multipart","urlencoded"],"created_at":"2024-12-04T03:09:06.047Z","updated_at":"2026-05-04T06:33:38.073Z","avatar_url":"https://github.com/unematiii.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fastify-simple-form\n\n[![Build Status](https://travis-ci.org/unematiii/fastify-simple-form.svg)](https://travis-ci.org/unematiii/fastify-simple-form)\n[![Coverage Status](https://coveralls.io/repos/github/unematiii/fastify-simple-form/badge.svg)](https://coveralls.io/github/unematiii/fastify-simple-form)\n[![View on npm](https://img.shields.io/npm/v/fastify-simple-form)](https://www.npmjs.com/package/fastify-simple-form)\n[![View on npm](https://img.shields.io/npm/dw/fastify-simple-form)](https://www.npmjs.com/package/fastify-simple-form)\n[![GitHub license](https://img.shields.io/github/license/unematiii/fastify-simple-form)](https://github.com/unematiii/fastify-simple-form/blob/main/LICENSE)\n\nFastify plugin that adds content type parser for the `application/x-www-form-urlencoded` and/or `multipart/form-data` types.\n\n## Description\n\nEssentially a tiny wrapper around [busboy](https://github.com/mscdex/busboy), that parses `application/x-www-form-urlencoded` and/or `multipart/form-data` content types and attaches associated fields to `request.body`.\n\nNB! This plugin does not handle `files`, these get simply discarded as described [here](https://github.com/mscdex/busboy#busboy-special-events).\n\n## Install\n\n```\nnpm install fastify-simple-form\n```\n\n## TypeScript\n\nAlthough this package includes typings for the plugin itself, you must install ones for node.js and busboy manually:\n```\nnpm install @types/node @types/busboy --save-dev\n```\n\n## Usage \u0026 Options\n\n### Selectively enable content types to parse\n\n```js\nfastify.register(require('fastify-simple-form'), {\n  multipart: true,   // Enable parsing for `multipart/form-data`, default: true\n  urlencoded: false, // Disable parsing for `application/x-www-form-urlencoded`, default: true\n});\n```\n\nThis plugin has no effect when both options above are set to `false`.\n\n### Options for busboy\n\nOptions for busboy can be passed in using `busboyOptions` property which has identical shape to busboy [constructor](https://github.com/mscdex/busboy#busboy-methods), e.g.:\n\n```js\nfastify.register(require('fastify-simple-form'), {\n  busboyOptions: {\n    defCharset: 'utf8',\n    limits: {\n      fieldNameSize: 100, // Max field name size (in bytes), default: 100\n      fieldSize: 1000000, // Max field value size (in bytes), default: 1MB\n      fields: 10,         // Max number of non-file fields, default: Infinity\n      // ...\n    },\n  },\n});\n```\n\n### Prototype poisoning protection\n\n```js\nfastify.register(require('fastify-simple-form'), {\n  onConstructorPoisoning: 'ignore', // Possible values are 'error', 'remove' and 'ignore'\n  onProtoPoisoning: 'error'         // Possible values are 'error', 'remove' and 'ignore'\n});\n```\n\n- `onConstructorPoisoning`:\n  - `error` - throws SyntaxError when a `constructor` key is found\n  - `remove` - field will not be attached to `request.body`\n  - `ignore` - field be be attached to `request.body`\n- `onProtoPoisoning`:\n  - `error` - throw SyntaxError when a key matching any property name of `Object.prototype` (besides `constructor`) is found\n  - `remove` - field will not be attached to `request.body`\n  - `ignore` - field be be attached to `request.body`\n\nBoth options will default to what is defined on Fastify root instance (or Fastify own defaults) for safe parsing of JSON objects. See [`onConstructorPoisoning`](https://www.fastify.io/docs/latest/Server/#onprotopoisoning) and [`onProtoPoisoning`](https://www.fastify.io/docs/latest/Server/#onprotopoisoning).\n\n### Example\n\nGiven server \u0026 handler:\n\n```js\nimport Fastify from 'fastify';\nimport SimpleFormPlugin from 'fastify-simple-form';\n\nconst fastify = Fastify();\n\nfastify.register(SimpleFormPlugin);\n\nfastify.post(\n  '/token',\n  {\n    schema: {\n      body: {\n        type: 'object',\n        properties: {\n          username: {\n            type: 'string',\n          },\n          password: {\n            type: 'string',\n          },\n          grant_type: {\n            type: 'string',\n            enum: ['password'],\n          },\n        },\n        required: ['grant_type'],\n      },\n    },\n  },\n  (request, reply) =\u003e {\n    reply.send(request.body);\n  },\n);\n\nfastify.listen(3000);\n```\n\nThese requests would succeed:\n\n```sh\ncurl -F \"username=jon\" -F \"password=snow\" -F \"grant_type=password\" \\\n  localhost:3000/token\n```\n\n```sh\ncurl -d \"username=jon\" -d \"password=snow\" -d \"grant_type=password\" \\\n  localhost:3000/token\n```\n\nResponse:\n\n```json\n{\n  \"username\": \"jon\",\n  \"password\": \"snow\",\n  \"grant_type\": \"password\"\n}\n```\n\nWhile these won't pass the schema validation\n\n```sh\ncurl -F \"username=jon\" -F \"password=snow\" -F \"grant_type=refresh_token\" \\\n  localhost:3000/token\n```\n\n```sh\ncurl -d \"username=jon\" -d \"password=snow\" -d \"grant_type=refresh_token\" \\\n  localhost:3000/token\n```\n\nResponse\n\n```json\n{\n  \"statusCode\": 400,\n  \"error\": \"Bad Request\",\n  \"message\": \"body.grant_type should be equal to one of the allowed values\"\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funematiii%2Ffastify-simple-form","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Funematiii%2Ffastify-simple-form","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funematiii%2Ffastify-simple-form/lists"}