user2674150
user2674150

Reputation: 57

Understanding the body decorator in nestjs

Where is the object that references the @body payload stored?

If your user controller has a post function.

@Post() @HttpCode(HttpStatus.CREATED) create(@Body() user: IUserBase): Promise { return this.usersService.create(user); }

Where is the user variable stored? Is it stored in the request object of the nest.js server?

Upvotes: 2

Views: 3575

Answers (1)

Naor Levi
Naor Levi

Reputation: 1813

It is injected into the function as an argument.

The @body decorator basically says:
Please cast the json that arrives in the request body into IUserBase type and place it as a parameter to this controller's handler.

Upvotes: 3

Related Questions