Gathering detailed insights and metrics for fastify-raw-body
Gathering detailed insights and metrics for fastify-raw-body
npm install fastify-raw-body
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (95.49%)
TypeScript (4.51%)
Total Downloads
6,642,413
Last Day
3,812
Last Week
25,622
Last Month
210,606
Last Year
3,113,696
46 Stars
60 Commits
10 Forks
3 Watching
2 Branches
9 Contributors
Minified
Minified + Gzipped
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
Cumulative downloads
Total Downloads
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
3
5
Adds the raw body to the Fastify request object.
npm i fastify-raw-body
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 |
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.
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.
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
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
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
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