# Decorator Header
Decorator operation responseModule | import { Header } from "@tsed/schema" |
---|---|
Source | /packages/specs/schema/src/types/decorators/operations/header.ts |
# Overview
function Header(headers: string | number | JsonHeaders, value?: string | number | JsonHeader): Function;
# Description
Sets the response’s HTTP header field to value. To set multiple fields at once, pass an object as the parameter.
@Header('Content-Type', 'text/plain');
private myMethod() {}
@Status(204)
@Header({
"Content-Type": "text/plain",
"Content-Length": 123,
"ETag": {
"value": "12345",
"description": "header description"
}
})
private myMethod() {}
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
This example will produce the swagger responses object:
{
"responses": {
"204": {
"description": "Description",
"headers": {
"Content-Type": {
"type": "string"
},
"Content-Length": {
"type": "number"
},
"ETag": {
"type": "string",
"description": "header description"
}
}
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19