redux-rest-tools
v0.7.3
Published
Redux tools to handle REST requests
Downloads
30
Maintainers
Readme
Redux REST tools
Redux REST tools is an opinionated library to handle API calls in Redux apps. It provides action creators, reducers generator, state normalization and a middleware to handle the request flow... with the REST convention in mind. It is meant to ease HTTP requests and data handling while ensuring performance and state consistency.
REST action creators use redux-actions
under the hood to create FSA-complient set of actions. For each request, a request
, success
and fail
action creator will be generate with the possibility to pass success/failure handlers to deal with the consequences of a successful/failed API request.
REST reducers use immutable
objects for their slice of the state (but the whole state is not required to se immutable). They handle immutable and JS action payloads for state update, but immutable data structure are preferred to increase state update performance and reduce from/to JS conversion efforts (note: in a React app, you might avoid using toJS()
in mapStateToProps
to speed up UI refresh pace).
Each state slice managed by a REST reducer is normalized based on the entities' unique identifiers (e.g. the object ID, see idPath
). Their shapes look like { result: [...], entities: {...}, ui: {...}, errors: {...} }
, where result
is the list of entity IDs, entities
is an object where each key is an entity ID and its content is the entity itself, ui
is used to store request states, and errors
the errors that may occur during the API calls.
The REST middleware handles the async request flow. It starts with a request
action triggering the actual HTTP request using axios
. If the request succeed, the success
action is dispatched; else the fail
action is dispatched. To deal with the consequences of a successful/failed request, you may pass onSuccessAction
/onFailAction
action creators and onSuccess
/onFail
function in the request action meta to be called with the request results.
Installation
To install the stable version with npm:
npm install --save redux-rest-tools
or with yarn:
yarn add redux-rest-tools
Usage
Coming soon...
Documentation
Contribution & Feedback
redux-rest-tools
is at an early stage of development. You are more than welcome to provide feedback and contribute to the development of the project.
Please search the existing issues to follow up on open/closed discussions.
License
MIT