1.0.3 • Published 6 months ago

@hastom/fetch v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

A little sugar to Fetch API

Axios-like request methods:

import { fetcher } from '@hastom/fetch'

await fetcher.get('https://google.com')

Auto-stringify get-params:

import { fetcher } from '@hastom/fetch'

await fetcher('https://google.com', {
  params: {
    query: 'string',
    and: ['also', 'arrays']
  }
})

Auto-strigify body to json and set content-type to application/json:

import { fetcher } from '@hastom/fetch'

await fetcher.post('https://google.com', {
  body: {
    query: 'string',
    and: ['also', 'arrays']
  }
})

Create instances with default params:

import { createFetchInstance } from '@hastom/fetch'

const authorizedFetch = createFetchInstance({
  headers: {
    Authorization: 'Bearer ...',
  },
})

await authorizedFetch.get('https://my-api.com/private-data')

and set base url:

import { createFetchInstance } from '@hastom/fetch'

const myApi = createFetchInstance({
  baseURL: 'https://my-api.com',
})

await myApi.get('/important-data')
1.0.3

6 months ago

1.0.2

8 months ago

1.0.1

9 months ago

1.0.0

9 months ago