Variable: fetch
constfetch:FetchWithMethods
Defined in: packages/fetch/src/index.ts:123
A fetch() replacement that simplifies data fetching with automatic JSON parsing, request timeouts, retries, and powerful interceptors. It also includes deferred and throttled request capabilities for complex asynchronous control flows.
Will reject promise if response status code is not 2xx (200 <= status < 300).
Param
Param
(optional) all built-in fetch() options such as "method", "headers" and the additionals below.
Param
(optional) if not provided AbortController will be instantiated when timeout used.
Param
(optional) request headers. Default: { 'content-type' : 'application/json'}
Param
(optional) request interceptor callbacks. See FetchInterceptors for details.
Param
(optional) Default: "get"
Param
(optional) duration in milliseconds to abort the request if it takes longer.
Param
(optional) specify how to parse the result. Default: FetchAs.json For raw Response use FetchAs.response
Example
import { fetch } from '@superutils/fetch'
// no need for `response.json()` or `result.data.theActualData` drilling
fetch('https://dummyjson.com/products/1').then(theActualData => console.log(theActualData))