# BodyParams Decorator

Module
import { BodyParams } from "@tsed/common"
Source/packages/common/src/mvc/decorators/params/bodyParams.ts

# Overview

function BodyParams(expression: string, useType: Type<any>): ParameterDecorator;
function BodyParams(expression: string): ParameterDecorator;
function BodyParams(useType: Type<any>): ParameterDecorator;
function BodyParams(options: IParamOptions<any>): ParameterDecorator;
function BodyParams(): ParameterDecorator;
Param Type Description
expression string The path of the property to get. useType

# Description

BodyParams return the value from request.body object.

# Example

@Controller('/')
class MyCtrl {
   @Post('/')
   create(@BodyParams() body: any) {
      console.log('Entire body', body);
   }

   @Post('/')
   create(@BodyParams('id') id: string) {
      console.log('ID', id);
   }

   @Post('/')
   create(@BodyParams('user') user: User) { // with deserialization
      console.log('user', user);
   }

   @Post('/')
   create(@BodyParams('users', User) users: User[]) { // with deserialization
      console.log('users', users);
   }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

For more information on deserialization see converters page.