1.1.4 • Published 8 months ago

@russh/fetch-api v1.1.4

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

Fetch with access token refresh

npm

A simple wrapper around the Fetch API with

  • Access token refresh on 401 response status
  • Shorthands
  • RTK baseQuery
  • JSON to FormData converter (requires custom middleware on backend)

Install

npm i @russh/fetch-api

Usage

First create an instance of the FetchApi class with a base URL and optionally a path name to refresh the access token.

const api = new FetchApi('https://example.com', '/refresh-token')

Then use full declaration...

const result = await api.fetch({ url: '/path', method: 'POST', body: { foo: 'bar' } })

...or shorthand to get fetch data

await api.get('/path')
await api.post('/path', { foo: 'bar' })
await api.patch('/path/id', { foo: 'bar' })
await api.delete('/path/id')

The instance also contains fetch-api based RTK baseQuery

export const apiName = createApi({
    reducerPath: 'apiName',
    baseQuery: api.baseQuery,
    endpoints: (builder) => ({
    ...
    })
})
1.1.4

8 months ago

1.1.3

9 months ago

1.1.2

10 months ago

1.1.1

11 months ago

1.0.0

12 months ago