1.0.12 • Published 1 year ago
@fiizy/fitch v1.0.12
fitch - wrapper for fetch
Usage
NPM
npm i @fiizy/fitch
Import
import { Fitch } from '@fiizy/fitch'
const apiService = new Fitch({
baseURL: 'https://example.com'
})
apiService.get('/test-path')
apiService.delete('/test-path')
apiService.post('/test-path', payload)
apiService.put('/test-path', payload)
Examples
Different transformers can be used before fetch is done.
const apiService = new Fitch({
baseURL: 'https://example.com',
transformRequest: [transformToSnake, authHeader],
transformResponse: [transformToCamel],
headers: { 'accept-encoding': 'gzip' }
})
Auth header transformer example
function authHeader(request: JsonObject): any {
request.headers = { ...request.headers, Authorization: `Bearer ${accessToken}` }
return request
}