redux-api-utility-library
v1.0.4
Published
A utility library for handling API Requests and Async Actions with Redux
Downloads
5
Readme
Redux API Utility Library (RAUL)
Redux API Utility Library (RAUL) is a library of higher order reducers, an API middleware, TypeScript data types, and other utility functions to make building a Redux Application involving asynchronous calls to RESTful APIs more simple.
Install
npm i --save redux-api-utility-library
Higher Order Reducers
import { createRequestReducer } from 'redux-api-utility-library/dist/reducers'
const users = createRequestReducer('users')
Now there is a reducer created fully equipped to deal with all the standard actions dispatched by the apiMiddleware
.
Middleware
import { apiMiddleware } from 'redux-api-utility-library/dist/middleware'
const store = createStore(
users: createRequestReducer('users'),
{},
applyMiddleware(apiMiddleware),
)
Action creators
import { createRequestAction } from 'redux-api-utility-library/dist/actions'
const action = createRequestAction('users', {
method: 'GET',
url: '/users',
baseURL: 'https://jsonplaceholder.typicode.com',
})
this action when dispatched get handled by the apiMiddleware
makes the network requests equivalent to the keys passed in as the second argument.