# Header Decorator

Module
import { Header } from "@tsed/common"
Source/packages/common/src/mvc/decorators/method/header.ts

# Overview

function Header(headerName: string | number | IHeadersOptions, headerValue?: string | number | IResponseHeader): 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

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