# REST Actions

<!-- **REST action creators** use `redux-actions` under the hood to create FSA-complient set of actions (`{ type: string payload?: any, meta?: any }`). For each request, a `request`, `success` and `fail` action creator will be generate. The meta may contain `onSuccessAction`, `onSuccess`, `onFailAction`, `onFail` actions/action creators/functions to deal with the consequences of a successful/failed API request. -->

## API

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

### createRequestActions

Creates request, success and fail action creators to handle the REST request for that collection and verb.

**Parameters**

-   `collection` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The name of the collection.
-   `verb` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The verb defining the request type (find, findOne, create, update, delete).

Returns **RequestActions** An object containing the request, success and fail action creators.

### createReducerActions

Creates clear and clearErrors action creators to alter portion of the state relative to the collection.

**Parameters**

-   `collection` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The name of the collection.

Returns **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** And object containing the clear and clearErrors action creators.

### createRestActions

Creates REST action creators (request, success and fail) for each verb of that collection and to manage that portion of the state.

**Parameters**

-   `config` **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** The configuration object, `{ collection: string, verbs: [string] }`, where the `collection` key is the name of the collection and the verbs is an array of verb (`find`, `findOne`, `create`, `update` or `delete`) for which the REST actions will be generated.

Returns **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** An object containing the REST action creators corresponding to each verb and the reducer action creators.

### handlerCreator

Creates the handler function to handle the REST request actions (request, success, fail).

**Parameters**

-   `verb` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The verb to handle (find, findOne, create, update or delete).
-   `requestActions` **RequestActions** An object containing the request, success and fail action creators to handle.
-   `idPath` **IdPath** The path to the value to identify the REST entities (string, string array, function or string with dot separation).

Returns **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** An object containing the functions to handle request, success and fail state change in the reducer.

### restReducer

Creates a REST reducer to handle the defined actions.

**Parameters**

-   `config` **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** The REST reducer config with the following keys: `idPath`, the path to the identifier of the requested objects (string, array of string or function); `actions`: the REST actions to handle; `extraHandlers`: an object where each key is the action type to handle and each key contains a function to handle the state change for these actions.

Returns **Reducer** A reducer to handle REST requests state changes.

### getEntities

Gets the entities from the state.

**Parameters**

-   `reducerSubState` **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** the part of the state handled by the REST reducer.
-   `options` **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)?= getEntitiesOptionsDefault** the options may contain: `immutable` (boolean, defaults to true) to define if JS (requires a `toJS` conversion) or immutable objects (better for performance) should be returned; `reverse` (boolean, defaults to false) to return the objects in reverse order.

Returns **oject** The entities from the state (immutable list or JS array depending on the configuration).

### getEntity

Gets an entity from the state.

**Parameters**

-   `reducerSubState` **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** the part of the state handled by the REST reducer.
-   `key` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the key of the entity to retrieve (the value returned by the specified `idPath`).
-   `options` **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)?= getEntityOptionsDefault** the options to use. `immutable`: boolean to specify if the returned object should be immutable (defaults to true).

Returns **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** The entity (immutable map or JS array depending on the configuration).

### getStatus

Gets the status of the request.

**Parameters**

-   `reducerSubState` **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** the part of the state handled by the REST reducer.
-   `status` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** one of `finding`, `findingOne`, `creating`, `updating` or `deleting`.
-   `key` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** (optional) - the key of the entity (the value returned by the specified `idPath`).

Returns **[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** `true` if the request is pending, else `false`.
