Class HTTP

A set of utilities to work with HTTP requests and responses.

Constructors

Properties

_logger: SimpleLogger

The service used to log information in the terminal.

_nodeFetch: ((url, init?) => Promise<Response>)

The node-fetch library. Since it's an ESM only module, Jimpex loads it on boot and makes it available on the container.

Type declaration

    • (url, init?): Promise<Response>
    • Parameters

      • url: URL | RequestInfo
      • Optional init: RequestInit

      Returns Promise<Response>

_options: HTTPOptions

The service customization options.

Accessors

Methods

  • Logs a request information into the terminal.

    Parameters

    • url: string

      The request URL.

    • options: RequestInit

      The options for the request.

    Returns void

  • Logs a response information into the terminal.

    Parameters

    • response: Response

      The response to log.

    Returns void

  • Makes a fetch request.

    Parameters

    • url: string

      The URL to fetch.

    • options: HTTPFetchOptions = {}

      The custom options for the request.

    Returns Promise<Response>

  • Creates a dictionary with all the custom headers a request has. By custom header it means all the headers which name start with x-.

    Parameters

    • req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>

      The request from which it will try to get the headers.

    • options: GetCustomHeadersFromRequestOptions = {}

      The options to customize the behavior with certain headers.

    Returns Record<string, string>

  • Tries to get the IP address from a given request.

    Parameters

    • req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>

      The request from which it will try to obtain the IP address.

    Returns undefined | string

  • It takes a dictionary of headers and normalize the names so each word will start with an upper case character. This is helpful in case you added custom headers and didn't care about the casing, or when copying headers from a server request, as they all come tranformed into lower case.

    Parameters

    • headers: Record<string, string>

      The dictionary of headers to normalize.

    Returns Record<string, string>

Generated using TypeDoc