@wavesenterprise/fetch
v1.0.2
Published
Light wrapper around Fetch API
Downloads
3
Readme
A little sugar to Fetch API
Axios-like request methods:
import { weFetch } from '@wavesenterprise/fetch'
await weFetch.get('https://google.com')
Auto-stringify get-params:
import { weFetch } from '@wavesenterprise/fetch'
await weFetch('https://google.com', {
params: {
query: 'string',
and: ['also', 'arrays']
}
})
Auto-strigify body to json and set content-type to application/json:
import { weFetch } from '@wavesenterprise/fetch'
await weFetch.post('https://google.com', {
body: {
query: 'string',
and: ['also', 'arrays']
}
})
Create instances with default params:
import { createFetchInstance } from '@wavesenterprise/fetch'
const authorizedFetch = createFetchInstance({
headers: {
Authorization: 'Bearer ...',
},
})
await authorizedFetch.get('https://my-api.com/private-data')
and set base url:
import { createFetchInstance } from '@wavesenterprise/fetch'
const myApi = createFetchInstance({
baseURL: 'https://my-api.com',
})
await myApi.get('/important-data')