axios-redux-middleware
This is a tiny redux middleware which allows you to make http requests(using axios) by dispatching actions.
Installation
npm install npm i axios-promise-redux-middleware --save
Usage
Step-1
Add the middleware to your store
; const store = ;
Step-2
Use it in your actions. Example:
const login = type: 'LOGIN' axios: true// You need to specify this, if you want to make a http request options: // url: '/login' // can be relative or absolute method: 'post' data: username: email password ;
For options, refer Axios Options
If the http requests is successful then action with SUCCESS suffix is dispatched, else action with FAILED suffix is dispatched.
Step 3
Write Reducers for the actions
Example
; const defaultState = ; LOGIN_SUCCESS: { if actionerror === false if actionpayloaduser return Object; return state; } Object
Acknowledgements
Inspired by redux-axios-middleware