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.
npm i --save redux-api-utility-library
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
.
import { apiMiddleware } from 'redux-api-utility-library/dist/middleware'
const store = createStore(
users: createRequestReducer('users'),
{},
applyMiddleware(apiMiddleware),
)
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.