I have this test request using the VS Code REST Client extension:
PATCH http://localhost:3000/auth/3
content-type: application/json
{ "email": "[email protected]" }
On the receiving end, the NestJS app listening on this endpoint isn't picking up the body of the PATCH request, so there's no update within the NestJS service responsible for update requests.
Here's the controller method/endpoint in NestJS:
@Patch('/:id')
updateUser(@Param('id') id: string, @Body() body: UpdateUserDto) {
console.log('body: ', body);
return this.usersService.update(parseInt(id), body);
}
And the result of the debugging console log above:
body: {}
Thanks!
The extra line between the URI request and the request headers was the problem. One must put the request headers directly after the URI as such:
PATCH http://localhost:3000/auth/3
content-type: application/json
{ "email": "[email protected]" }
Reading the section on request headers on the VS Code REST Client Extension page, the author clearly states:
The lines immediately after the request line to first empty line are parsed as Request Headers
Then the body comes through as expected:
body: { email: '[email protected]' }
Hope this saves someone else the time it took me to figure it out.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With