Decorator
BodyParamsModule | 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);
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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.