# Header Decorator operation response
Module | import { Header } from "@tsed/common" |
---|---|
Source | /packages/common/src/mvc/decorators/method/header.ts |
# Overview
function Header(headerName: string | number | IHeadersOptions, headerValue?: IHeaderOptions): 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
- Session & cookies
- Passport.js
- TypeORM
- Mongoose
- GraphQL
- Socket.io
- Swagger
- AJV
- Multer
- Serve static files
- Templating
- Throw HTTP Exceptions
- Customize 404
- AWS
- Jest
- Seq
- Controllers
- Providers
- Model
- Converters
- Middlewares
- Pipes
- Interceptors
- Authentication
- Hooks
- Injection scopes
- Custom providers
- Custom endpoint decorator
- Testing