This class implements the HttpClient interface using the Fetch API.

The SimpleHttpClient allows making HttpMethod requests with timeout and base URL configuration.

Implements

Constructors

  • Constructs an instance of SimpleHttpClient with the given base URL, timeout period and HTTP headers. The HTTP headers are used each time this client send a request to the URL, if not overwritten by the HttpParams of the method sending the request.

    Parameters

    • baseURL: string

      The base URL for HTTP requests.

    • Optionalheaders: HeadersInit = ...

      The default headers for HTTP requests.

    • Optionaltimeout: number = SimpleHttpClient.DEFAULT_TIMEOUT

      The timeout duration in milliseconds.

    Returns SimpleHttpClient

Properties

baseURL: string

Return the root URL for the API endpoints.

headers: HeadersInit
timeout: number

Return the amount of time in milliseconds before a timeout occurs when requesting with HTTP methods.

DEFAULT_TIMEOUT = 30000

Represent the default timeout duration for network requests in milliseconds.

Methods

  • Sends an HTTP GET request to the specified path with optional query parameters.

    Parameters

    Returns Promise<unknown>

    A promise that resolves with the response of the GET request.

  • Executes an HTTP request with the specified method, path, and optional parameters.

    Parameters

    • method: HttpMethod

      The HTTP method to use for the request (e.g., GET, POST).

    • path: string

      The URL path for the request. Leading slashes will be automatically removed.

    • Optionalparams: HttpParams

      Optional parameters for the request, including query parameters, headers, body, and response validation. HttpParams.headers override SimpleHttpClient.headers.

    Returns Promise<unknown>

    A promise that resolves to the response of the HTTP request.

    Throws an error if the HTTP request fails.

  • Makes an HTTP POST request to the specified path with optional parameters.

    Parameters

    Returns Promise<unknown>

    A promise that resolves with the response from the server.