4.1.2 • Published 7 years ago

redux-api-mapper v4.1.2

Weekly downloads
5
License
MIT
Repository
github
Last release
7 years ago

redux-api-mapper

NPM Version

Motivation

Many react/redux applications need to interact with an api. To solve this problem with redux, we use middlewares that are able to handle async actions, such as a http request. Using this approach is not wrong, however, sometimes it generates a lot of boilerplate. Especially when handling api requests.

Solution

Redux-Api-Mapper for rescue! It's a small but powerful utility for mapping any api with a simple config definition. You can create an object with methods for accessing your api. It will automatically dispatch actions for your reducers based on the state of the request. This library also create an apiReducer so you don't have to create any reducer or actions by hand.

Documentation (4.1.x)

Examples

Install

npm install --save redux-api-mapper

Quick Start

Consider the github api. We could map this api with a config like this

var config = {
  host : "https://api.github.com",
  resources : [
	{
		name : 'Repos',
		path : '/',
		endPoints : [
			{
				name : 'getRepos',
				path : 'users/{username}/repos'
			}
		]
	}
  ]
}

This is a common javascript object. The cool parts to notice here is the /users/{username}/repos in the end point. Redux-Api-Mapper will automatically fullfill these parameter when making the request. Here is a full example:

import { createMapper } from 'redux-api-mapper';
import { store } from './yourstorefile';

// Define the config
const config = /*...*/

// Create your api mapper
const api = createMapper(store, config);

// Use your api
api.Repos.getRepos({username : 'gugamm'}).then(repos => console.log(repos));

Depending on how you are using this library, you can take advantage of the built-in api reducer, provide your own or use an external one. When making the request, the library will automatically dispatch actions to your reducers depending on the state of the request.

4.1.2

7 years ago

4.1.1

7 years ago

4.1.0

7 years ago

4.0.0

7 years ago

3.7.2

7 years ago

3.7.1

7 years ago

3.7.0

7 years ago

3.6.3

7 years ago

3.6.2

7 years ago

3.6.1

7 years ago

3.6.0

7 years ago

3.5.2

7 years ago

3.5.1

7 years ago

3.5.0

7 years ago

3.4.0

7 years ago

3.3.2

7 years ago

3.2.1

7 years ago

3.1.1

7 years ago

3.1.0

7 years ago

3.0.0

7 years ago

2.1.1

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.2.3

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago