Installations
npm install fastify-raw-body
Developer Guide
Typescript
Yes
Module System
CommonJS
Min. Node Version
>= 10
Node Version
20.8.0
NPM Version
10.1.0
Releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (95.49%)
TypeScript (4.51%)
Developer
Eomm
Download Statistics
Total Downloads
6,642,413
Last Day
3,812
Last Week
25,622
Last Month
210,606
Last Year
3,113,696
GitHub Statistics
46 Stars
60 Commits
10 Forks
3 Watching
2 Branches
9 Contributors
Bundle Size
280.89 kB
Minified
156.51 kB
Minified + Gzipped
Sponsor this package
Package Meta Information
Latest Version
5.0.0
Package Id
fastify-raw-body@5.0.0
Unpacked Size
25.33 kB
Size
5.83 kB
File Count
8
NPM Version
10.1.0
Node Version
20.8.0
Publised On
17 Sept 2024
Total Downloads
Cumulative downloads
Total Downloads
6,642,413
Last day
-4.9%
3,812
Compared to previous day
Last week
-41.9%
25,622
Compared to previous week
Last month
-7.7%
210,606
Compared to previous month
Last year
61.4%
3,113,696
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
3
Dev Dependencies
5
fastify-raw-body
Adds the raw body to the Fastify request object.
Install
npm i fastify-raw-body
Compatibility
Plugin version | Fastify version |
---|---|
^5.0.0 | ^5.0.0 |
^4.2.1 | ^4.19.0 |
^4.0.0 | ^4.0.0 |
^3.0.0 | ^3.0.0 |
^2.0.0 | ^2.0.0 |
Usage
This plugin will add the request.rawBody
.
It will get the data using the preParsing
hook.
1import Fastify from 'fastify' 2 3const app = Fastify() 4await app.register(import('fastify-raw-body'), { 5 field: 'rawBody', // change the default request.rawBody property name 6 global: false, // add the rawBody to every request. **Default true** 7 encoding: 'utf8', // set it to false to set rawBody as a Buffer **Default utf8** 8 runFirst: true, // get the body before any preParsing hook change/uncompress it. **Default false** 9 routes: [], // array of routes, **`global`** will be ignored, wildcard routes not supported 10 jsonContentTypes: [], // array of content-types to handle as JSON. **Default ['application/json']** 11}) 12 13app.post('/', { 14 config: { 15 // add the rawBody to this route. if false, rawBody will be disabled when global is true 16 rawBody: true 17 }, 18 handler (req, reply) { 19 // req.rawBody the string raw body 20 reply.send(req.rawBody) 21 } 22})
Note
You need toawait
the plugin registration to make sure the plugin is ready to use. All the routes defined before the plugin registration will be ignored. This change has been introduced in Fastify v4.
Warning
Settingglobal: false
and then the route configuration{ config: { rawBody: true } }
will save memory of your server since therawBody
is a copy of thebody
and it will double the memory usage.
So use it only for the routes that you need to.
Raw body as Buffer
It is important to know that setting encoding: false
will run addContentTypeParser
to add a content type parser for application/json
.
This is needed since the default content type parser will set the encoding of the request stream to { parseAs: 'string' }
.
If you haven't customized this component, it will be secure as the original one since secure-json-parse
is used under the hood.
License
Copyright Manuel Spigolon, Licensed under MIT.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 3/15 approved changesets -- score normalized to 2
Reason
1 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/ci.yml:1
- Warn: no topLevel permission defined: .github/workflows/release.yml:1
- Info: no jobLevel write permissions found
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:22: update your workflow using https://app.stepsecurity.io/secureworkflow/Eomm/fastify-raw-body/release.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:23: update your workflow using https://app.stepsecurity.io/secureworkflow/Eomm/fastify-raw-body/release.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/release.yml:27: update your workflow using https://app.stepsecurity.io/secureworkflow/Eomm/fastify-raw-body/release.yml/main?enable=pin
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 third-party GitHubAction dependencies pinned
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 22 are checked with a SAST tool
Score
4
/10
Last Scanned on 2025-01-13
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More