<commit_before># redux-axios-reducers

[![npm version](https://badge.fury.io/js/redux-axios-reducers.svg)](https://badge.fury.io/js/redux-axios-reducers)

Redux reducers for fetching data with axios HTTP client

## Installation

```bash
npm install --save redux-axios-reducers
```

## How to use?

### Configure and connect an Axios reducer

```js

import {createStore, combineReducers} from 'redux';
import {AxiosReducer} from redux-axios-reducer;

const usersReducer = new AxiosReducer({name: 'users'});

const client = axios.create({
  baseURL:'http://localhost:8080/api',
  responseType: 'json'
});

const reducers = combineReducers({
    users: usersReducer.configure(client);
    // application reducers
    ...
});

const store = createStore(reducers)

```

### Dispatch actions

A reducer instance has methods which generate actions and do HTTP requests.

```js

// HTTP GET /api/users
loadUsers = () => usersReducer.get()

loadUsersWithFilter = (status) => usersReducer.get({
    // See Axios documentation for params
    params: {
        status: status
    }
})

// HTTP PUT /api/users/1
updateUsers = (id, data) => usersReducer.put({
    url: 'users/' + id,
    data: data
})

// Redux-thunk middleware
loadUsers = () => (dispatch) => {
    dispatch(
        usersReducer.get()
    ).then( () => {
        // do something else
    })
}

```

### Reduce actions

A reducer is generating TYPES based on given name:

```js

    reducerInstance.TYPES
    {
        FETCHING: `ASYNC/${name.toUpperCase()}/FETCHING`
        FETCH_ERROR: `ASYNC/${name.toUpperCase()}/FETCH_ERROR`
        FETCH_SUCCESS: `ASYNC/${name.toUpperCase()}/SUCCESS`
        
    }
```

So you can use it in your own reducers like `usersReducer.TYPES.FETCH_SUCCESS`
<commit_msg>Minor fixes.<commit_after># redux-axios-reducers

[![npm version](https://badge.fury.io/js/redux-axios-reducers.svg)](https://badge.fury.io/js/redux-axios-reducers)

Redux reducers for fetching data with axios HTTP client

## Installation

```bash
npm install --save redux-axios-reducers
```

## How to use?

### Configure and connect an Axios reducer

```js

import {createStore, combineReducers} from 'redux';
import {AxiosReducer} from redux-axios-reducer;

const usersReducer = new AxiosReducer({name: 'users'});

const client = axios.create({
  baseURL:'http://localhost:8080/api',
  responseType: 'json'
});

const reducers = combineReducers({
    users: usersReducer.configure(client);
    // application reducers
    ...
});

const store = createStore(reducers)

```

### Dispatch actions

A reducer instance has methods which generate actions and do HTTP requests.

```js

// HTTP GET /api/users
loadUsers = () => usersReducer.get()

loadUsersWithFilter = (status) => usersReducer.get({
    // See Axios documentation for params
    params: {
        status: status
    }
})

// HTTP PUT /api/users/1
updateUsers = (id, data) => usersReducer.put({
    url: 'users/' + id,
    data: data
})

// Redux-thunk middleware
loadUsers = () => (dispatch) => {
    dispatch(
        usersReducer.get()
    ).then( () => {
        // do something else
    })
}

```

### Reduce actions

A reducer is generating TYPES based on given name:

```js

    reducerInstance.TYPES
    // {
    //     FETCHING: `ASYNC/${name.toUpperCase()}/FETCHING`
    //     FETCH_ERROR: `ASYNC/${name.toUpperCase()}/FETCH_ERROR`
    //     FETCH_SUCCESS: `ASYNC/${name.toUpperCase()}/SUCCESS`
    //     
    // }
```

So you can use it in your own reducers like `usersReducer.TYPES.FETCH_SUCCESS`

{'fraction_non_alphanumeric': 0.1492495043896913, 'fraction_numerical': 0.002832058906825262, 'mean_word_length': 3.2916160388821387, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5662529', 'n_tokens_mistral': 1266, 'n_tokens_neox': 1210, 'n_words': 285}