@mvdlei/web/fetch
A simplified and upgraded fetch tool.
API Documentation
Introduction
This module provides an extended version of the fetch
function with defaults for headers and base URL.
Usage
With parameters
API Reference
api(input: Request | string | URL, init?: ApiInit): Promise<ApiResponse>
Extended version of fetch with defaults for headers and the base URL.
input
: The input to be called, which can be a URL, string, or Request object.init
: The options for the request.- Returns:
Promise<ApiResponse>
- The response from the request.
api.post(input: Request | string | URL, init?: ApiInit): Promise<ApiResponse>
Makes a POST request using the api
function.
api.put(input: Request | string | URL, init?: ApiInit): Promise<ApiResponse>
Makes a PUT request using the api
function.
api.patch(input: Request | string | URL, init?: ApiInit): Promise<ApiResponse>
Makes a PATCH request using the api
function.
api.del(input: Request | string | URL, init?: ApiInit): Promise<ApiResponse>
Makes a DELETE request using the api
function.
api.get(input: Request | string | URL, init?: ApiInit): Promise<ApiResponse>
Makes a GET request using the api
function.
ApiInit
Interface for initializing the API.
params?: Record<string, string> | URLSearchParams | string | null | undefined
: The parameters added to the URL.origin?: string
: Base URL for the request.baseUrl?: string
: Base URL for the request (same asorigin
but with a different name).path?: string
: Base path for the request.
ApiResponse
Interface representing the response from the API.
data: unknown
: The data received in the response.status: number
: The status code of the response.