# Cookies Decorator

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

# Overview

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

# Description

Cookies or CookiesParams return the value from request.cookies object.

# Example

@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);
   }
}
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.