• Imports one or more HTTP request header into an argument / parameter of a handler as key/value pair.

    Parameters

    • Optional transformer: ParameterDataTransformer

      The custom transformer function to use.

    • Optional Rest ...names: string[]

      One or more headers to import. If the list is empty, all headers are taken.

    Returns ParameterDecorator

    The new decorator function.

    Example

    // index.ts

    import { Controller, ControllerBase, GET, Headers, IHttpRequest, IHttpResponse, Request, Response } from '@egomobile/http-server'

    interface IHeaders {
    "x-ego-1": string;
    "x-ego-2": number;
    "x-ego-3": boolean;
    }

    @Controller()
    export default class IndexController extends ControllerBase {
    @GET('/foo/:bar/buzz')
    async getBar(
    @Headers(({ key, source }) => {
    if (key === 'x-ego-2') {
    return Number(source)
    } else if (key === 'x-ego-3') {
    return Boolean(source)
    }

    return source
    }, 'x-ego-1', 'x-ego-2', 'x-ego-3') importedHeaders: IHeaders,

    @Response() response: IHttpResponse
    ) {
    response.write(`x-ego-1: ${importedHeaders['x-ego-1']} (${typeof importedHeaders['x-ego-1']})\n`)
    response.write(`x-ego-2: ${importedHeaders['x-ego-2']} (${typeof importedHeaders['x-ego-2']})\n`)
    response.write(`x-ego-3: ${importedHeaders['x-ego-3']} (${typeof importedHeaders['x-ego-3']})\n`)
    }
    }
  • Parameters

    • Rest ...names: string[]

    Returns ParameterDecorator

Generated using TypeDoc