# Decorator BodyParams

Decorator operation input private
Module
import { BodyParams } from "@tsed/platform/platform-params/src/decorators/bodyParams"
Source/packages/platform/platform-params/src/decorators/bodyParams.ts

# Overview

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

# Description

BodyParams return the value from request.body (opens new window) 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.

Other topics