@nurislamov/micro-fetch
TypeScript icon, indicating that this package has built-in type declarations

0.0.3 • Public • Published

Micro-Fetch status

A tiny zero-dependencies http methods library.

Size

~300B gzipped

Requirements

  • fetch (native browser support or node-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

Readme

Keywords

none

Package Sidebar

Install

npm i @nurislamov/micro-fetch

Weekly Downloads

1

Version

0.0.3

License

MIT

Unpacked Size

28 kB

Total Files

15

Last publish

Collaborators

  • nurislamov