export namespace http { /** * Make a request with any method. * @template [T=any] * @param {HttpMethod} method HTTP method * @param {string} url Request URL * @param {any} [data] Body - JSON-encoded unless FormData, URLSearchParams, Blob, ArrayBuffer/view or a stream. Not sent for GET/HEAD. * @param {RequestOptions} [config] Request options * @returns {Promise} The response body */ export function request(method: HttpMethod, url: string, data?: any, config?: RequestOptions): Promise; /** * Make a GET request. * @template [T=any] * @param {string} url Request URL * @param {RequestOptions} [config] Request options * @returns {Promise} The response body */ export function get(url: string, config?: RequestOptions): Promise; /** * Make a POST request. * @template [T=any] * @param {string} url Request URL * @param {any} [data] Request body (JSON-encoded unless a raw body such as FormData) * @param {RequestOptions} [config] Request options * @returns {Promise} The response body */ export function post(url: string, data?: any, config?: RequestOptions): Promise; /** * Make a PUT request. * @template [T=any] * @param {string} url Request URL * @param {any} [data] Request body (JSON-encoded unless a raw body such as FormData) * @param {RequestOptions} [config] Request options * @returns {Promise} The response body */ export function put(url: string, data?: any, config?: RequestOptions): Promise; /** * Make a PATCH request. * @template [T=any] * @param {string} url Request URL * @param {any} [data] Request body (JSON-encoded unless a raw body such as FormData) * @param {RequestOptions} [config] Request options * @returns {Promise} The response body */ export function patch(url: string, data?: any, config?: RequestOptions): Promise; /** * Make a DELETE request. DELETE sends no body unless one is given as `config.data`. * @template [T=any] * @param {string} url Request URL * @param {DeleteRequestOptions} [config] Request options * @returns {Promise} The response body */ function _delete(url: string, config?: DeleteRequestOptions): Promise; export { _delete as delete }; /** * Make a HEAD request. * @template [T=any] * @param {string} url Request URL * @param {RequestOptions} [config] Request options * @returns {Promise} The response body */ export function head(url: string, config?: RequestOptions): Promise; /** * Make a OPTIONS request. * @template [T=any] * @param {string} url Request URL * @param {RequestOptions} [config] Request options * @returns {Promise} The response body */ export function options(url: string, config?: RequestOptions): Promise; } /** * Options for a request. Anything not listed by name here is passed to `fetch()` as it is. */ export type RequestOptions = Omit & RequestOwnOptions; /** * The options Domma reads itself (the rest of {@link RequestOptions} goes to `fetch()`). */ export type RequestOwnOptions = { /** * Request headers (plain object, `Headers` or entry pairs); copied, never mutated. * `Content-Type: application/json` is added for a JSON body unless one is given. */ headers?: HeadersInit | undefined; /** * Do not log a failure to the console (useful for expected errors such as a 401 check). */ silent?: boolean | undefined; /** * Abort after this many milliseconds (rejects with a `TimeoutError`). */ timeout?: number | undefined; /** * Defaults to `'same-origin'`; pass `'include'` to send cookies cross-origin. */ credentials?: RequestCredentials | undefined; /** * Abort signal, composed with `timeout` (whichever fires first aborts). */ signal?: AbortSignal | undefined; mode?: RequestMode | undefined; cache?: RequestCache | undefined; redirect?: RequestRedirect | undefined; referrer?: string | undefined; referrerPolicy?: ReferrerPolicy | undefined; integrity?: string | undefined; keepalive?: boolean | undefined; }; /** * Options for `http.delete()`: a body is sent only when given as `data`. */ export type DeleteRequestOptions = RequestOptions & { data?: any; }; /** * The error a failed request rejects with: the server's `message` (or `error`) from a JSON body, * otherwise `HTTP Error: `. */ export type HttpError = Error & { status?: number; statusText?: string; body?: any; }; export type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "OPTIONS" | (string & {}); /** * Fetch-based HTTP client. Every method resolves to the response BODY (not a response object): * parsed JSON for a JSON or unlabelled body, text for any other type, `null` when there is no body * (204/205/304, HEAD, an empty body). A non-2xx status rejects with an {@link HttpError}. */ export type Http = typeof http;