@Header

The {@link oaj.http.annotation.Header @Header} annotation is used to retrieve request headers.

- {@link oaj.http.annotation.Header}
  - {@link oaj.http.annotation.Header#_default() _default} - Default value if not present.
  - {@link oaj.http.annotation.Header#_enum() _enum} - Input validation. Must match one of the values.
  - {@link oaj.http.annotation.Header#allowEmptyValue() allowEmptyValue} - Input validation. Allow empty value.
  - {@link oaj.http.annotation.Header#api() api} - Free-form Swagger JSON.
  - {@link oaj.http.annotation.Header#collectionFormat() collectionFormat} - How collections of items are formatted.
  - {@link oaj.http.annotation.Header#description() description} - Description.
  - {@link oaj.http.annotation.Header#example() example} - Serialized example.
  - {@link oaj.http.annotation.Header#exclusiveMaximum() exclusiveMaximum} - Input validation. Whether maximum is exclusive.
  - {@link oaj.http.annotation.Header#exclusiveMinimum() exclusiveMinimum} - Input validation. Whether minimum is exclusive.
  - {@link oaj.http.annotation.Header#format() format} - The schema type format.
  - {@link oaj.http.annotation.Header#items() items} - The schema of items in a collection.
  - {@link oaj.http.annotation.Header#maximum() maximum} - Input validation. Maximum numeric value.
  - {@link oaj.http.annotation.Header#maxItems() maxItems} - Input validation. Maximum number of items in a collection.
  - {@link oaj.http.annotation.Header#maxLength() maxLength} - Input validation. Maximum length of a string.
  - {@link oaj.http.annotation.Header#minimum() minimum} - Input validation. Minimum numeric value.
  - {@link oaj.http.annotation.Header#minItems() minItems} - Input validation. Minimum number of items in a collection.
  - {@link oaj.http.annotation.Header#minLength() minLength} - Input validation. Minimum length of a string.
  - {@link oaj.http.annotation.Header#multipleOf() multipleOf} - Input validation. Number must be a multiple of.
  - {@link oaj.http.annotation.Header#name() name} - Header name.
  - {@link oaj.http.annotation.Header#parser() parser} - Override the part parser.
  - {@link oaj.http.annotation.Header#pattern() pattern} - Input validation. Must match regular expression.
  - {@link oaj.http.annotation.Header#required() required} - Input validation. Header must be present.
  - {@link oaj.http.annotation.Header#type() type} - The schema type.
  - {@link oaj.http.annotation.Header#uniqueItems() uniqueItems} - Input validation. Collections must contain unique items only.
  - {@link oaj.http.annotation.Header#value() value} - Free-form Swagger JSON.

The most typical scenario is to simply use the value field to define header parameter names:

##### Example:

@RestMethod(name=GET) public void doGet(@Header("ETag") UUID etag) {...}

This is functionally equivalent to the following code:

@RestMethod(name=GET) public void doGet(RestRequest req) { RequestHeaders h = req.getHeaders(); UUID etag = h.get("ETag", UUID.class); }

The special name "*" (or blank) can be used to represent all values. When used, the data type must be a Map or bean.

##### Examples:

// Multiple values passed as a map. @RestMethod(name=GET) public void doGet(@Header("*") Map<String,Object> map) {...}

// Same, but name "*" is inferred. @RestMethod(name=GET) public void doGet(@Header Map<String,Object> map) {...}

// Multiple values passed as a bean. @RestMethod(name=GET) public void doGet(@Header MyBean bean) {...}

The registered {@link oajr.RestContext#REST_partParser REST_partParser} is used to convert strings to POJOs and controls what POJO types are supported. By default, this is the {@link oaj.oapi.OpenApiParser} which supports the standard Swagger-based rules for parsing.

For example, the following shows how a pipe-delimited list of comma-delimited numbers (e.g. "1,2,3|4,5,6|7,8,9") can be converted to a 2-dimensional array of Longs:

@RestMethod(method="GET", path="/testHeader") public void testHeader( @Header( name="My-Header", collectionFormat="pipes", items=@SubItems( collectionFormat="csv", type="integer", format="int64", minimum="0", maximum="100" minLength=1, maxLength=10 ), minLength=1, maxLength=10 ) Long[][] myHeader ) {...}

Input will be converted based on the types and formats defined in the schema definition. Input validations such as minLength/maxLength that don't match the input will result in automatic 400 Bad Request responses.

For more information about valid parameter types, see {@doc juneau-marshall.OpenApiDetails.Parsers OpenAPI Parsers}

The @Header annotation is also used for supplying swagger information about the HTTP part. This information is used to populate the auto-generated Swagger documentation and UI.

##### Examples:

// Normal @Header( name="Pet-Name", description="Pet name", required=true, example="Doggie" )

// Free-form // Note the extra field @Header( name="Pet-Name", api={ "description: 'Pet name',", "required: true,", "example: 'Doggie'," "x-extra: 'extra field'" } )

{@doc DefaultRestSvlVariables} (e.g. "$L{my.localized.variable}") are supported on annotation fields.

##### Example:

@Header( description="$L{PetNameDescription}" )

- {@link oajr.RequestHeaders}
- {@doc juneau-rest-server.OpenApiSchemaPartParsing}