Type Alias: FetchInterceptorRequest
FetchInterceptorRequest =
Interceptor<FetchArgs[0],FetchArgsInterceptor>
Defined in: packages/fetch/src/types.ts:134
Fetch request interceptor to be invoked before making a fetch request. This interceptor can also be used as a transformer:
- by returning an API URL (string/URL)
- by modifying the properties of the options object to be used before making the fetch request
Example
typescript
import PromisE from '@superutils/promise'
// update API version number
const apiV1ToV2 = url => `${url}`.replace('api/v1', 'api/v2')
const includeAuthToken = (url, options) => {
options.headers.set('x-auth-token', 'my-auth-token')
}
const data = await PromisE.fetch('https://my.domain.com/api', {
interceptors: {
result: [apiV1ToV2, includeAuthToken]
}
})