@xylabs/fetch
v5.1.2
Published
JSON-configured fetch with optional gzip compression via pako
Downloads
28,647
Readme
@xylabs/fetch
JSON-configured fetch with optional gzip compression via pako
Install
Using npm:
npm install {{name}}Using yarn:
yarn add {{name}}Using pnpm:
pnpm add {{name}}Using bun:
bun add {{name}}License
See the LICENSE file for license rights and limitations (LGPL-3.0-only).
Reference
packages
fetch
### .temp-typedoc
### functions
### <a id="fetchCompress"></a>fetchCompressfunction fetchCompress(url, options?): Promise<Response>;Drop-in replacement for native fetch that optionally gzip-compresses the request body.
When compressLength is set and the body string exceeds that threshold, the body is
gzip-compressed via pako and Content-Encoding: gzip is added to the headers.
Returns a standard Response — identical to what native fetch returns.
Parameters
url
string | URL
options?
FetchCompressOptions = {}
Returns
Promise<Response>
### <a id="fetchJson"></a>fetchJsonfunction fetchJson<T>(url, options?): Promise<FetchJsonResponse<T>>;JSON-configured fetch with optional gzip compression on request bodies.
Request bodies exceeding compressMinLength bytes are gzip-compressed via pako.
Type Parameters
T
T
Parameters
url
string
options?
FetchCompressOptions = {}
Returns
Promise<FetchJsonResponse<T>>
### <a id="fetchJsonDelete"></a>fetchJsonDeletefunction fetchJsonDelete<T>(url, options?): Promise<FetchJsonResponse<T>>;JSON DELETE request.
Type Parameters
T
T
Parameters
url
string
options?
Returns
Promise<FetchJsonResponse<T>>
### <a id="fetchJsonGet"></a>fetchJsonGetfunction fetchJsonGet<T>(url, options?): Promise<FetchJsonResponse<T>>;JSON GET request.
Type Parameters
T
T
Parameters
url
string
options?
Returns
Promise<FetchJsonResponse<T>>
### <a id="fetchJsonPatch"></a>fetchJsonPatchfunction fetchJsonPatch<T>(
url,
data?,
options?): Promise<FetchJsonResponse<T>>;JSON PATCH request with a body.
Type Parameters
T
T
Parameters
url
string
data?
unknown
options?
Returns
Promise<FetchJsonResponse<T>>
### <a id="fetchJsonPost"></a>fetchJsonPostfunction fetchJsonPost<T>(
url,
data?,
options?): Promise<FetchJsonResponse<T>>;JSON POST request with a body.
Type Parameters
T
T
Parameters
url
string
data?
unknown
options?
Returns
Promise<FetchJsonResponse<T>>
### <a id="fetchJsonPut"></a>fetchJsonPutfunction fetchJsonPut<T>(
url,
data?,
options?): Promise<FetchJsonResponse<T>>;JSON PUT request with a body.
Type Parameters
T
T
Parameters
url
string
data?
unknown
options?
Returns
Promise<FetchJsonResponse<T>>
### interfaces
### <a id="FetchCompressOptions"></a>FetchCompressOptionsExtends
RequestInit
Properties
compressMinLength?
optional compressMinLength?: number;Gzip payloads larger than this byte count. Requires pako to be installed.
### <a id="FetchJsonResponse"></a>FetchJsonResponseStructured response from a fetchJson call.
Type Parameters
T
T
Properties
data
data: T | null;headers
headers: Headers;response
response: Response;status
status: number;statusText
statusText: string; ### type-aliases
### <a id="FetchJsonOptions"></a>FetchJsonOptionstype FetchJsonOptions = FetchCompressOptions;Fetch request options extended with an optional gzip compression threshold.
