import type { RestApiConfig } from '../definitions/interfaces.js'; import type { RequestMethod, WriteMode } from '../definitions/types.js'; import { FetchError } from './fetch-error.js'; import type { FetchResponse } from './fetch-response.js'; import { Status } from './status.js'; /** * The RestAPI class manages the requests to a REST API. * * - The base URL of the API is automatically concatenated to the path of the requests. * - The config of the API is automatically merged with the config of the requests. * - The status of the requests is automatically tracked and can be accessed through the status property. * - The requests are sent with the Fetch class, so all features of the Fetch class are available. * * [Aracna Reference](https://aracna.dariosechi.it/core/classes/rest-api) */ export declare class RestAPI { /** * The base URL of the REST API. */ protected baseURL: string; /** * The default config of the REST API. */ protected config: T; /** * The status of the requests. */ readonly status: Status; constructor(baseURL?: string, config?: T); /** * Sends a request to the REST API. */ protected send(method: RequestMethod, path: string, body?: W, config?: T): Promise | FetchError>; /** * Sends a CONNECT request to the REST API. */ connect(path: string, config?: T): Promise | FetchError>; /** * Sends a DELETE request to the REST API. */ delete(path: string, config?: T): Promise | FetchError>; /** * Sends a GET request to the REST API. */ get(path: string, config?: T): Promise | FetchError>; /** * Sends a HEAD request to the REST API. */ head(path: string, config?: T): Promise; /** * Sends an OPTIONS request to the REST API. */ options(path: string, config?: T): Promise | FetchError>; /** * Sends a PATCH request to the REST API. */ patch(path: string, body?: W, config?: T): Promise | FetchError>; /** * Sends a POST request to the REST API. */ post(path: string, body?: W, config?: T): Promise | FetchError>; /** * Sends a PUT request to the REST API. */ put(path: string, body?: W, config?: T): Promise | FetchError>; /** * Sends a TRACE request to the REST API. */ trace(path: string, config?: T): Promise; /** * Sends a POST request if the mode is 'create' or a PUT request if the mode is 'update' to the REST API. */ write(mode: WriteMode, path: string, body?: W, config?: T): Promise | FetchError>; /** * Transforms the body of the request. */ transformBody(method: RequestMethod, path: string, body: V | undefined, config: T): Promise; /** * Transforms the query parameters of the request. */ transformQueryParameters(method: RequestMethod, path: string, body: V | undefined, config: T): Promise; /** * Handles the error of the request. */ handleError(method: RequestMethod, path: string, body: V | undefined, config: T, error: FetchError): Promise; /** * Handles the pending state of the request. */ handlePending(method: RequestMethod, path: string, body: V | undefined, config: T): Promise; /** * Handles the success of the request. */ handleSuccess(method: RequestMethod, path: string, body: W | undefined, config: T, response: FetchResponse): Promise; /** * Sets the status of the request. */ protected setCallStatus(method: RequestMethod, path: string, config: T, status: string): void; getBaseURL(): string; getConfig(): T; setBaseURL(baseURL: string): this; setConfig(config: T): this; /** * Checks if the config status is settable. */ protected isConfigStatusSettable(config: RestApiConfig, status: string): boolean; }