For a hashing and verification purpose, raw body (without parsing) of a application/json
post request is needed.
Does loopback 4 provide any method for that? Request.body
is parsed as a json.
Asked
Active
Viewed 763 times
1 Answers
7
You can get the raw body by providing the following requestBodySpec
:
@post('/raw-body-post')
async rawBodyPost(
@requestBody({
description: 'Raw Body', // Description can be anything
required: true,
content: {
'application/json': { // Make sure this matches the POST request type
'x-parser': 'raw', // This is the key to skipping parsing
schema: {type: 'object'},
},
},
}) body: Buffer
) {
const rawBody = body.toString('utf8');
...
}

modelDBA
- 176
- 1
- 8