Cookies
@tsed/platform-params
Usage
typescript
import { Cookies } from "@tsed/platform-params";
See /packages/platform/platform-params/src/types/decorators/cookies.ts.
Overview
ts
function Cookies(expression: string, useType: Type<any>): ParameterDecorator;
export function Cookies(expression: string): ParameterDecorator;
export function Cookies(useType: Type<any>): ParameterDecorator;
export function Cookies(options: Partial<ParamOptions>): ParameterDecorator;
export function Cookies(): ParameterDecorator;
expression (
string
): The path of the property to get.useType (
Type<any>
): The type of the class that to be used to deserialize the data.
Description
Cookies or CookiesParams return the value from request.cookies object.
Example
typescript
@Controller('/')
class MyCtrl {
@Post('/')
create(@Cookies() body: any) {
console.log('Entire body', body);
}
@Post('/')
create(@Cookies('id') id: string) {
console.log('ID', id);
}
@Post('/')
create(@Cookies('user') user: User) { // with deserialization
console.log('user', user);
}
@Post('/')
create(@Cookies('users', User) users: User[]) { // with deserialization
console.log('users', users);
}
}
For more information on deserialization see converters page.