{"id":17436239,"url":"https://github.com/bsnext/fastify-payload","last_synced_at":"2026-03-27T03:09:46.613Z","repository":{"id":257825171,"uuid":"872156438","full_name":"bsnext/Fastify-Payload","owner":"bsnext","description":"Plugin for adding raw-body data as 'request.payload' field into Fastify Requests.","archived":false,"fork":false,"pushed_at":"2025-06-06T08:59:52.000Z","size":16,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-06T09:36:49.525Z","etag":null,"topics":["body","fastify","nodejs","payload","plugin","raw","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bsnext.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-10-13T23:19:54.000Z","updated_at":"2025-06-06T08:59:55.000Z","dependencies_parsed_at":"2024-12-05T21:20:09.627Z","dependency_job_id":"1b0dec1b-aa3f-44ff-b21d-6be9ff76f5af","html_url":"https://github.com/bsnext/Fastify-Payload","commit_stats":{"total_commits":2,"total_committers":1,"mean_commits":2.0,"dds":0.0,"last_synced_commit":"baf5e0fca646880dda694011abffec60307e64fa"},"previous_names":["bsnext/fastify-payload"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/bsnext/Fastify-Payload","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bsnext%2FFastify-Payload","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bsnext%2FFastify-Payload/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bsnext%2FFastify-Payload/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bsnext%2FFastify-Payload/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bsnext","download_url":"https://codeload.github.com/bsnext/Fastify-Payload/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bsnext%2FFastify-Payload/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262018759,"owners_count":23245619,"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":["body","fastify","nodejs","payload","plugin","raw","typescript"],"created_at":"2024-10-17T10:07:18.903Z","updated_at":"2026-03-27T03:09:46.583Z","avatar_url":"https://github.com/bsnext.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Fastify-Payload\n![Build \u0026 Test](https://github.com/bsnext/fastify-payload/actions/workflows/test.yml/badge.svg)\n![Node.JS Supported](https://badgen.net/static/Node.JS/%3E=19.0.0/green)\n![Fastify Supported](https://badgen.net/static/Fastify/%3E=4.14.0/green)\n![Install Size](https://badgen.net/packagephobia/install/@bsnext/fastify-payload)\n![Dependencies](https://badgen.net/bundlephobia/dependency-count/@bsnext/fastify-payload)\n![License](https://badgen.net/static/license/MIT/blue)\n\nPlugin for adding raw-body data as 'request.payload' field into Fastify Requests.\u003cbr\u003e\n\n**Tested on Fastify v4.14+ and Node.JS v19+!**\u003cbr\u003e\nhttps://github.com/bsnext/fastify-payload/actions/workflows/test.yml\n\nThis parser do not have external dependencies, only \"@fastify/plugin\". Also, **it use default secure JSON parser fron Fastify**, with defined by server rules about prototype/constructor poisoning. \n\nThis plugin Supported adding extra \"Content-Type's\" and custom parsers.\u003cbr\u003e\nAnd that only one reason, why i not use [that](https://github.com/Eomm/fastify-raw-body).\n\n## Installing:\n```bash\nnpm install @bsnext/fastify-payload\n```\n\n## Usage:\n```ts\nimport FastifyPayload from '@bsnext/fastify-payload'; // TS\nimport { default as FastifyPayload } from \"@bsnext/fastify-payload\"; // MJS\nconst { default: FastifyPayload } = require(`@bsnext/fastify-payload`); // CJS\n\nconst server = Fastify();\nawait server.register(FastifyPayload, {\n\t// Use plugin for all paths\n\t// Do not use \"true\" in production\n\t// Every request with existed payload - will eat memory\n\tglobal: boolean = false; \n\n \t// Specific paths for save payload\n\tpaths: string[] = [];\n\n\t// Payload format\n\tparse: `string`|`buffer` = `buffer`; \n\n\t// Content-Type parsers. Possible add and use more parsers (XML, JSON5, ...).\n\t// \"default\" option only for \"application/json\", \"text/plain\" or \"*\".\n\t// Enabled for \"application/json\" only by default.\n\t// Default parser for \"*\" will accept any Content-Type on Fastify Server!\n\tcontentTypes?: {\n\t\t// Use \"default\" if wanna use default parser.\n\t\t// Or write custom parser by function.\n\t\t[key: string]: 'default' | function(request, payload, callback: (err, result));\n\t\t[`application/json`]: 'default';\n\t};\n\n\t// Plugin will output warnings when overwritten content parsers\n\t// It 100% will output warning about \"application/json\" overwrite\n\t// In 99.9% you need set \"false\" by hands. \n\t// If make \"false\" by default - it can be a head-pain reason for somebody.\n\toverwriteWarning?: boolean = true;\n});\n\nserver.post(url, {\n\tconfig: {\n\t\t// Save payload in this route?\n\t\t// Default \"false\" for everything.\n\t\t// Of course if not use \"global: true\" in plugin.\n\t\tpayload: boolean = false\n\t}\n}, function() {\n\t...\n})\n\n```\n\n```ts\n// Important note about modify default \"contentParsers\" object.\n// You should send all object if want enable \"text/plain\" or add new parser\nawait server.register(FastifyPayload, \n\t{\n\t\tcontentParsers: {\n\t\t\t[`application/json`]: 'default';\n\t\t\t[`application/xml`]: function(...) {... your xml parse code};\n\t\t}\n\t}\n);\n\n// If object not will have a \"application/json\" - it not will parse that.\n// This code will disable plugin for all, and left only \"application/xml\".\nawait server.register(FastifyPayload, \n\t{\n\t\tcontentParsers: {\n\t\t\t[`application/xml`]: function(...) {...};\n\t\t}\n\t}\n);\n```\n\nMore information about Fastify Content-Type Parsing:\nhttps://fastify.dev/docs/v5.0.x/Reference/Server/#addcontenttypeparser\n\n## Example: Regular Usage\n\n```ts\nimport Fastify from 'fastify'; \nimport FastifyPayload from '@bsnext/fastify-payload'; \n\nconst server = Fastify(...);\nawait server.register(FastifyPayload);\n\nserver.post(`/request_with_payload`, {\n\tconfig: { payload: true }\n}, function(request, response) {\n\tconsole.log(`request.payload -\u003e`, request.payload);\n\tresponse.send(`ok`);\n})\n\nserver.listen({ port: 8080 });\n\n```\n\n## Example: Weird, But Possible Usage\n\n```ts\nimport Fastify from 'fastify'; \nimport FastifyPayload from '@bsnext/fastify-payload'; \n\nconst server = Fastify(...);\nawait server.register(FastifyPayload, {\n\tpaths: [`/request_with_payload`, `/one_more_request_with_payload`]\n});\n\nserver.post(`/request_with_payload`, function(request, response) {\n\tconsole.log(`request.payload -\u003e`, request.payload);\n\tresponse.send(`ok`);\n})\n\nserver.patch(`/one_more_request_with_payload`, function(request, response) {\n\tconsole.log(`request.payload -\u003e`, request.payload);\n\tresponse.send(`ok`);\n})\n\n// Options for save payload can be shuffled: \"paths\" + \"configs\"\nserver.put(`/last_request_with_payload`, {\n\tconfig: { payload: true }\n}, function(request, response) {\n\tconsole.log(`request.payload -\u003e`, request.payload);\n\tresponse.send(`ok`);\n})\n\nserver.listen({ port: 8080 });\n\n```\n\n## Example: Adding Extra Parser\n\n```ts\nimport Fastify from 'fastify'; \nimport FastifyPayload from '@bsnext/fastify-payload'; \n\nimport { xml2js } from 'xml-js';\n\nconst server = Fastify();\nawait server.register(FastifyPayload, {\n\tcontentTypes: {\n\t\t[`application/json`]: 'default',\n\t\t[`application/xml`]: function (request, payload, done) {\n\t\t\ttry {\n\t\t\t\tdone(null, xml2js(payload));\n\t\t\t} catch (error) {\n\t\t\t\tdone(error);\n\t\t\t}\n\t\t}\n\t}\n});\n\nserver.post(`/convert_xml_to_json`, {\n\tconfig: { payload: true }\n}, function (request, response) {\n\tconsole.log(`request.payload -\u003e`, request.payload);\n\t/*\n\trequest.payload -\u003e \u003chi\u003e\n\t\t\u003ctext\u003eHow are you?\u003c/text\u003e\n\t\u003c/hi\u003e\n\t*/\n\tresponse.send(request.body);\n\t/*\n\t{\n\t\t\"elements\": [\n\t\t\t{ \"type\": \"element\", \"name\": \"hi\", \"elements\": [...] }\n\t\t]\n\t}\n\t*/\n});\n\nserver.listen({ port: 8080 });\n\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbsnext%2Ffastify-payload","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbsnext%2Ffastify-payload","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbsnext%2Ffastify-payload/lists"}