The RestApi class provides a simplified interface for making HTTP requests to a specified server using Axios. It supports common HTTP methods and manages authorization headers.

Constructors

Properties

Methods

Constructors

Properties

axios: Axios
HttpMethod: {
    DELETE: "DELETE";
    GET: "GET";
    PATCH: "PATCH";
    POST: "POST";
    PUT: "PUT";
} = ...

Enum-like object defining supported HTTP methods. This is a constant object that maps HTTP method names to their string representations.

Available methods:

  • GET: Fetch data from the server.
  • POST: Submit data to the server.
  • PUT: Replace data on the server.
  • PATCH: Partially update data on the server.
  • DELETE: Remove data from the server.

Methods

  • Sends an HTTP request to the server using the specified method and URL.

    Parameters

    • method:
          | "GET"
          | "DELETE"
          | "POST"
          | "PUT"
          | "PATCH"

      The HTTP method to use (GET, POST, PUT, PATCH, DELETE).

    • url: string

      The endpoint URL (relative to the base URL).

    • Optionalbody: any

      Optional data to send in the request body (used with POST, PUT, PATCH).

    Returns Promise<any>

    A promise that resolves to the server's response data.

    Logs and throws the error if the request fails.