redux-declarative-request-axios
v0.0.4
Published
Making axios requests following declarative programming paradigm leveraging redux actions structure
Downloads
8
Maintainers
Readme
Overview :
Still under development. It is not yet mature. Thank you for your understanding!
Install
npm install axios --save; # since it was put in peer dependencies
npm install redux-declarative-request-axios --save;
Example :
import { createStore } from 'redux';
import { declarativeAxios } from 'redux-declarative-request-axios';
const axiosMiddleWare = declarativeAxios({
baseUrl: 'https://myapi.example.com/api'
});
const store = createStore(reducers, axiosMiddleWare)
Then the action creator will look like the following:
function fetchPosts() {
return {
type: 'FETCH_POSTS',
uri: '/posts',
method: 'get',
// all config options of axios are applied here (headers,... so on)
'200': (req, res) => ({payload: res.data}),
'401': (req, res) => ({message: 'not authorized'})
}
}
Then, in reducer , you will be able to read action.payload
if ok, and action.message
if not ok with code 401 .. and so on.
It needs more documentation. However, currently we don't have time to write those things.
License:
MIT .