The BasicHttpClient class provides a simplified HTTP client for making requests to a server. It abstracts away the underlying HTTP client and the complexities of handling different response types and error handling, making it easier to interact with HTTP APIs.

This class includes static methods for:

  • Validating HTTP status codes.
  • Throwing custom error responses.
  • Handling JSON, text, and array buffer responses.
  • Selecting the appropriate response handler based on the expected response type.

The BasicHttpClient is designed to be used in scenarios where you need to make HTTP requests and handle responses in a consistent and predictable manner. It ensures that responses are correctly parsed and that errors are properly propagated, allowing for robust error handling.

This class relies on the cross-fetch library for making HTTP requests, and it uses custom error and header types defined in the project.

Hierarchy (view full)

Constructors

  • A basic http client with the option of adding default headers, and the option of using a baseUrl. Note: If the path given starts with https://, the baseUrl is ignored.

    It handles query parameters, and request body data which gets encoded as json if needed.

    See HttpRequest.

    Parameters

    • baseUrl: string

    Returns BasicHttpClient

Methods