Type Alias: FetchInterceptorRequest
FetchInterceptorRequest =
Interceptor<FetchArgs[0], [FetchArgsInterceptor[1]]>
Defined in: packages/fetch/src/types/interceptors.ts:85
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 parameter to be used before making the fetch request
Example
Intercept and transform fetch request
typescript
import fetch from '@superutils/fetch'
// 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 result = await fetch.get('[DUMMYJSON-DOT-COM]/products', {
method: 'post',
interceptors: {
result: [apiV1ToV2, includeAuthToken]
}
})