JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 39
  • Score
    100M100P100Q44586F
  • License MIT

Api middleware for React Native.

Package Exports

  • redux-api-middleware-native

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (redux-api-middleware-native) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Redux api middleware native

Redux api middleware for redux compatible with native and web apps.

Install

npm install --save redux-api-middleware-native

Adding middleware to redux store

import { createStore, applyMiddleware, combineReducers } from 'redux';
import apiMiddleware from 'redux-api-middleware-native';
import reducers from './reducers';

const reducer = combineReducers(reducers);
const initialState = {};

const store = createStore(reducer, initialState, applyMiddleware(
    apiMiddleware,
));

Example

import { API_REQUEST } from 'redux-api-middleware-native';

function action() {
    return {
            [API_REQUEST]: {
                url: 'http://www.example.com/resource',
                method: "POST",
                headers: {
                  'Content-Type': 'application/json'
                },
                body: {
                    'username' : 'npm-user',
                    'password' : 'test'
                },
                action: {
                        success: "SUCCESS",
                        failure: "FAILURE",
                        error: "ERROR"
                },
                meta: {
                  id: 'to reducer'
                }
            }
    }
}

Action Types

SUCCESS

Type success means your request get HTTP status code 200 without any other errors.

Action {
    type = action.success
    payload = JSON parsed response
    error = false
}

FAILURE

Type failure means your request not get HTTP status code 200 without any other errors.

Action {
    type = action.failure
    payload = JSON parsed response
    error = true
}

ERROR

Type error means we got exception on some point of code (ex. response parsing).

Action {
    type = action.error
    payload = ERROR object
    error = true
}