BodyParams Decorator

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

Overview

function BodyParams(expression?: string | any, useType?: any): Function;
Param Type Description
expression string | any Optional. 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);
   }
}

For more information on deserialization see converters page.