@@ -8,8 +8,6 @@ Adds the raw body to the Fastify request object.
88
99## Install
1010
11- ### Fastify v3
12-
1311```
1412npm i fastify-raw-body
1513```
@@ -20,6 +18,7 @@ npm i fastify-raw-body
2018| ------------- | :---------------:|
2119| ` ^2.0.0 ` | ` ^2.0.0 ` |
2220| ` ^3.0.0 ` | ` ^3.0.0 ` |
21+ | ` ^4.0.0 ` | ` ^4.0.0 ` |
2322
2423
2524## Usage
@@ -28,10 +27,10 @@ This plugin will add the `request.rawBody`.
2827It will get the data using the [ ` preParsing ` ] ( https://www.fastify.io/docs/latest/Reference/Hooks/#preparsing ) hook.
2928
3029``` js
31- const Fastify = require (' fastify' )
32- const app = Fastify ()
30+ import Fastify from ' fastify'
3331
34- app .register (require (' fastify-raw-body' ), {
32+ const app = Fastify ()
33+ await app .register (import (' fastify-raw-body' ), {
3534 field: ' rawBody' , // change the default request.rawBody property name
3635 global: false , // add the rawBody to every request. **Default true**
3736 encoding: ' utf8' , // set it to false to set rawBody as a Buffer **Default utf8**
@@ -51,10 +50,15 @@ app.post('/', {
5150})
5251```
5352
54- Notice: Setting ` global: false ` and then the route configuration ` { config: { rawBody: true } } ` will
55- save memory of your server since the ` rawBody ` is a copy of the ` body ` and it will double the memory usage.
53+ > ** Note**
54+ > You need to ` await ` the plugin registration to make sure the plugin is ready to use.
55+ > All the routes defined ** before** the plugin registration will be ignored.
56+ > This change has been introduced in Fastify v4.
5657
57- So use it only for the routes that you need to.
58+ > ** Warning**
59+ > Setting ` global: false ` and then the route configuration ` { config: { rawBody: true } } ` will
60+ > save memory of your server since the ` rawBody ` is a copy of the ` body ` and it will double the memory usage.
61+ > So use it only for the routes that you need to.
5862
5963### Raw body as Buffer
6064
0 commit comments