Skip to content

Function: fetchResponse()

fetchResponse<T, TOptions, TAs, TReturn>(url, options?): IPromisE<TReturn>

Defined in: packages/fetch/src/fetchResponse.ts:20

Drop-in replacement for built-in fetch() with with timeout, retry etc options and Response as default return type.

Type Parameters

T

T = Response

TOptions

TOptions extends FetchOptions = FetchOptions

TAs

TAs extends FetchAs = TOptions["as"] extends FetchAs ? any[any] : response

TReturn

TReturn = FetchResult<T>[TAs]

Parameters

url

request URL

string | URL

options?

Omit<RequestInit, "body"> & object & Omit<Partial<RetryOptions>, "retry" | "retryIf"> & object & TOptions

(optional) Standard fetch options extended with "FetchCustomOptions"

Returns

IPromisE<TReturn>

Example

javascript
import { fetchResponse } from '@superutils/fetch'

fetchResponse('https://dummyjson.com/products/1')
    .then(response => response.json())
    .then(console.log, console.error)