{"id":15647447,"url":"https://github.com/eomm/fastify-raw-body","last_synced_at":"2025-04-04T10:04:17.167Z","repository":{"id":37956804,"uuid":"272210763","full_name":"Eomm/fastify-raw-body","owner":"Eomm","description":"Request raw body","archived":false,"fork":false,"pushed_at":"2025-03-10T17:53:02.000Z","size":70,"stargazers_count":47,"open_issues_count":2,"forks_count":10,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-04T09:37:08.299Z","etag":null,"topics":["body-parser","fastify","fastify-plugin","hacktoberfest","raw","strapi"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/Eomm.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},"funding":{"github":"Eomm"}},"created_at":"2020-06-14T13:46:07.000Z","updated_at":"2025-03-10T17:52:58.000Z","dependencies_parsed_at":"2024-06-18T14:39:17.307Z","dependency_job_id":"41bd5273-644c-49e3-89e9-7a30b4f47460","html_url":"https://github.com/Eomm/fastify-raw-body","commit_stats":{"total_commits":60,"total_committers":10,"mean_commits":6.0,"dds":0.6166666666666667,"last_synced_commit":"1ddef48a0cb7e8c7b5c9d284b83d66cf47bed474"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Eomm%2Ffastify-raw-body","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Eomm%2Ffastify-raw-body/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Eomm%2Ffastify-raw-body/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Eomm%2Ffastify-raw-body/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Eomm","download_url":"https://codeload.github.com/Eomm/fastify-raw-body/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247157280,"owners_count":20893220,"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-parser","fastify","fastify-plugin","hacktoberfest","raw","strapi"],"created_at":"2024-10-03T12:19:30.691Z","updated_at":"2025-04-04T10:04:17.145Z","avatar_url":"https://github.com/Eomm.png","language":"JavaScript","funding_links":["https://github.com/sponsors/Eomm"],"categories":[],"sub_categories":[],"readme":"# fastify-raw-body\n\n[![Build Status](https://github.com/Eomm/fastify-raw-body/workflows/ci/badge.svg)](https://github.com/Eomm/fastify-raw-body/actions)\n[![npm](https://img.shields.io/npm/v/fastify-raw-body)](https://www.npmjs.com/package/fastify-raw-body)\n[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)\n\nAdds the raw body to the Fastify request object.\n\n## Install\n\n```\nnpm i fastify-raw-body\n```\n\n### Compatibility\n\n| Plugin version | Fastify version |\n| ------------- |:---------------:|\n| `^5.0.0` | `^5.0.0` |\n| `^4.2.1` | `^4.19.0` |\n| `^4.0.0` | `^4.0.0` |\n| `^3.0.0` | `^3.0.0` |\n| `^2.0.0` | `^2.0.0` |\n\n\n## Usage\n\nThis plugin will add the `request.rawBody`.  \nIt will get the data using the [`preParsing`](https://www.fastify.io/docs/latest/Reference/Hooks/#preparsing) hook.\n\n```js\nimport Fastify from 'fastify'\n\nconst app = Fastify()\nawait app.register(import('fastify-raw-body'), {\n  field: 'rawBody', // change the default request.rawBody property name\n  global: false, // add the rawBody to every request. **Default true**\n  encoding: 'utf8', // set it to false to set rawBody as a Buffer **Default utf8**\n  runFirst: true, // get the body before any preParsing hook change/uncompress it. **Default false**\n  routes: [], // array of routes, **`global`** will be ignored, wildcard routes not supported\n  jsonContentTypes: [], // array of content-types to handle as JSON. **Default ['application/json']**\n})\n\napp.post('/', {\n  config: {\n    // add the rawBody to this route. if false, rawBody will be disabled when global is true\n    rawBody: true\n  },\n  handler (req, reply) {\n    // req.rawBody the string raw body\n    reply.send(req.rawBody)\n  }\n})\n```\n\n\u003e **Note**  \n\u003e You need to `await` the plugin registration to make sure the plugin is ready to use.\n\u003e All the routes defined **before** the plugin registration will be ignored.\n\u003e This change has been introduced in Fastify v4.\n\n\u003e **Warning**  \n\u003e Setting `global: false` and then the route configuration `{ config: { rawBody: true } }` will\n\u003e save memory of your server since the `rawBody` is a copy of the `body` and it will double the memory usage.  \n\u003e So use it only for the routes that you need to.\n\n### Raw body as Buffer\n\nIt is important to know that setting `encoding: false` will run [`addContentTypeParser`](https://www.fastify.io/docs/master/ContentTypeParser/) to add a content type parser for `application/json`.\n\nThis is needed since the default content type parser will set the encoding of the request stream to `{ parseAs: 'string' }`.\n\nIf you haven't customized this component, it will be secure as the original one since [`secure-json-parse`](https://www.npmjs.com/package/secure-json-parse) is used under the hood.\n\n## License\n\nCopyright [Manuel Spigolon](https://github.com/Eomm), Licensed under [MIT](./LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feomm%2Ffastify-raw-body","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feomm%2Ffastify-raw-body","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feomm%2Ffastify-raw-body/lists"}