Micro-Fetch
A tiny zero-dependencies http methods library.
Size
~300B
gzipped
Requirements
-
fetch
(native browser support ornode-fetch
like polyfill)
Get started
npm i @nurislamov/micro-fetch
# or
yarn add @nurislamov/micro-fetch
Typings
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>
Default headers
{
'Content-Type': 'application/json'
}
Default credentials
'include'
Using
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()
Development
yarn
yarn dev
Build
yarn build
Testing
yarn test