# Quickstart

```bash
npm i redux-rest-resource --save
```

1. Export created types, actions and reducers (eg. in `containers/Users/store/index.js`)

```javascript
import {createResource} from 'redux-rest-resource';

const hostUrl = 'https://api.mlab.com:443/api/1/databases/sandbox/collections';
const apiKey = 'xvDjirE9MCIi800xMxi4EKeTm8e9FUBR';

export const {types, actions, rootReducer} = createResource({
  name: 'user',
  url: `${hostUrl}/users/:id?apiKey=${apiKey}`
});
```

1. Import reducers in your store

```javascript
import {combineReducers} from 'redux';
import {rootReducer as usersReducer} from 'containers/Users/store';
export default combineReducers({
  users: usersReducer
});
```

1. Use provided actions inside connected components

```javascript
import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import {actions as userActions} from 'containers/Users/store';
import UserListItem from './UserListItem';

class UserList extends Component {
  componentDidMount() {
    const {actions} = this.props;
    actions.fetchUsers();
  }

  render() {
    const {actions, users} = this.props;
    return <ul>{users.map(user => <UserListItem key={user.id} user={user} {...actions} />)}</ul>;
  }
}

export default connect(
  // mapStateToProps
  state => ({users: state.users.items}),
  // mapDispatchToProps
  dispatch => ({
    actions: bindActionCreators({...userActions}, dispatch)
  })
)(UserList);
```

> Next, You can check [usage examples](/redux-rest-resource/examples.md)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mgcrea.gitbook.io/redux-rest-resource/usage/quickstart.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
