Function isHeaders

  • You must configure the generic argument T.

    Headers decoder with type checking (for express and fastify).

    typia.http.isHeaders() is a function decoding an header instance, with automatic type casting to the expected type. When property type be defined as boolean or number type, typia.http.headers() will cast the value to the expected type.

    Also, after decoding, typia.http.isHeaders() performs type checking to the decoded value by combining with is function. Therefore, when the decoded value is not following the T type, null value would be returned.

    By the way, as HTTP headers are not enough to express complex data structures, typia.http.headers() function has some limitations. If target type T is not following those restrictions, compilation errors would be occured.

    1. Type T must be an object type
    2. Do not allow dynamic property
    3. Property key must be lower case
    4. Property value cannot be null, but undefined is possible
    5. Only boolean, bigint, number, string or their array types are allowed
    6. By the way, union type never be not allowed
    7. Property set-cookie must be array type
    8. Those properties cannot be array type
    • age
    • authorization
    • content-length
    • content-type
    • etag
    • expires
    • from
    • host
    • if-modified-since
    • if-unmodified-since
    • last-modified
    • location
    • max-forwards
    • proxy-authorization
    • referer
    • retry-after
    • server
    • user-agent

    Type Parameters

    • T extends object

      Expected type of decoded value

    Parameters

    • input: Record<string, undefined | string | string[]>

      Query string or URLSearchParams instance

    Returns Resolved<T> | null

    Decoded headers object or null value

    Jeongho Nam - https://github.com/samchon