A tiny zero-dependencies http methods library.
~300B
gzipped
fetch
(native browser support ornode-fetch
like polyfill)
npm i @nurislamov/micro-fetch
# or
yarn add @nurislamov/micro-fetch
interface MFOptions {
baseUrl: string
fetchOptions?: Omit<RequestInit, 'method' | 'body'>
}
const { get } = microFetch(options: MFOptions)
get(path: string, options: Omit<RequestInit, 'method' | 'body'>): Promise<Response>
post(path: string, body: BodyInit, options: Omit<RequestInit, 'method' | 'body'>): Promise<Response>
{
'Content-Type': 'application/json'
}
'include'
import { microFetch } from 'micro-fetch'
/** ... */
const {
get,
post,
patch,
put,
remove
} = microFetch({
baseUrl: 'https://mysite.com/api',
fetchOptions: {
credentials: 'omit',
headers: {
/** ... */
}
}
})
const response = await get('pathname', { cache: 'no-cache' })
const data = await response.json()
yarn
yarn dev
yarn build
yarn test