> For the complete documentation index, see [llms.txt](https://bayazetyan.gitbook.io/rest-redux-module/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://bayazetyan.gitbook.io/rest-redux-module/api/redux-module.md).

# Redux Module

### ReduxModule settings

* [prefix](/rest-redux-module/api/redux-module.md#prefix)
* [defaultState](/rest-redux-module/api/redux-module.md#defaultstate)
* [responseMap](/rest-redux-module/api/redux-module.md#responsemap)

### Actions Props

* [key](/rest-redux-module/api/redux-module.md#key)
* [name](/rest-redux-module/api/redux-module.md#name)
* [idKey](/rest-redux-module/api/redux-module.md#idkey)
* [apiCall](/rest-redux-module/api/redux-module.md#apicall)
* [withoutStatus](/rest-redux-module/api/redux-module.md#withoutstatus)
* [returnResponse](/rest-redux-module/api/redux-module.md#returnresponse)
* [withoutResponse](/rest-redux-module/api/redux-module.md#withoutresponse)
* [alternativeResponse](/rest-redux-module/api/redux-module.md#alternativeresponse)
* [alternativeRequest](/rest-redux-module/api/redux-module.md#alternativerequest)
* [callback](/rest-redux-module/api/redux-module.md#callback)

#### prefix

This prefix will be setted on all actions in this module environment

| Type   | Required | Default value |
| ------ | -------- | ------------- |
| string | Yes      | -             |

#### defaultState

The default data for current state

| Type   | Required | Default value |
| ------ | -------- | ------------- |
| Object | No       | null          |

#### responseMap

This object is for setting the server response.&#x20;

***Default ResponseMapProps***

```javascript
{
  successStatusValue: 'success',
  message: 'message',
  errors: 'errors',
  status: 'status',
  data: 'data',
}
```

For example:

```javascript
// Your server answer is 
const serverResponse = {
    result: [],
    errorData: [],
    response_code: 0,
    messageText: null,
};

// Your responseMap should be
const responseMap = {
    data: 'result',
    errors: 'errorData',
    successStatusValue: 0,
    status: 'response_code',
    message: 'messageText',
}
```

| Type   | Required | Default value     |
| ------ | -------- | ----------------- |
| Object | No       | `RespnseMapProps` |

#### key

The name of the key in which the data will be stored&#x20;

| Type   | Required | Default value |
| ------ | -------- | ------------- |
| string | No       | data          |

#### name

The action name. Default value depends on the action type, for example if you use [`createAddAction`](/rest-redux-module/api/redux-module/createaddaction.md) default value will be `CREATE`

| Type   | Required | Default value         |
| ------ | -------- | --------------------- |
| string | No       | Depends on the action |

#### idKey

This parameter should be used only when using one of this methods createAddAction, createUpdateAction, createDeleteAction . This property is intended to find the desired item by some identifier.&#x20;

| Type   | Required | Default value |
| ------ | -------- | ------------- |
| string | optional | -             |

#### apiCall

This is an API call function, that returns a Promise (required). If you want to update the store without a request to the server you can skip this property. For the store update you need to send data the first argument of the action function.&#x20;

For example

```javascript
// When you not use apiCall property.
const { updateProductAction } = this.props;
const updatedData = { /* some data */ };

updateProductAction(updatedData); // After action the 'updatedData' saved in the store

```

| Type     | Required | Default value |
| -------- | -------- | ------------- |
| function | No       | -             |

#### withoutStatus

When no needed have status parameters.

| Type    | Required | Default value |
| ------- | -------- | ------------- |
| boolean | No       | -             |

#### returnResponse

When the server response have not structure and needed get all response data you can use this property.

| Type    | Required | Default value |
| ------- | -------- | ------------- |
| boolean | No       | -             |

#### withoutResponse

When there is no need to store updates after a request to the server.

| Type    | Required | Default value |
| ------- | -------- | ------------- |
| boolean | No       | -             |

#### alternativeResponse

When need use custom logic for response processing.

| Type     | Required | Default value | Arguments            |
| -------- | -------- | ------------- | -------------------- |
| function | No       | -             | `(response: Object)` |

#### alternativeRequest

When need use custom action or dispatch other actions.&#x20;

```javascript
const alternativeRequest = (dispatch, callFunctionArguments, actionType) => {
// When you will use this function you need remember
// Need use one of this statuses
const STATUS = 'SUCCES' || 'PENDING' || 'ERROR';

dispatch({
    type: `${actionType}_${STATUS}`,
    payload: {}
});
}
```

| Type     | Required | Default value | Arguments                                                                |
| -------- | -------- | ------------- | ------------------------------------------------------------------------ |
| function | No       | -             | `(dispatch: Function, callFunctionArguments: Array, actionType: string)` |

#### callback

When need call function after success response.

| Type     | Required | Default value | Arguments                                |
| -------- | -------- | ------------- | ---------------------------------------- |
| function | No       | -             | `(response: Object, dispatch: Function)` |

### Methods

* [createAction](/rest-redux-module/api/redux-module/createaction.md)
* [createAddAction](/rest-redux-module/api/redux-module/createaddaction.md)
* [createUpdateAction](/rest-redux-module/api/redux-module/createupdateaction.md)
* [createDeleteAction](/rest-redux-module/api/redux-module/createdeleteaction.md)
* [createClearAction](/rest-redux-module/api/redux-module/createclearaction.md)
