Giter VIP home page Giter VIP logo

call-api-middleware's Introduction

call-api-middleware

Installation

npm install --save call-api-middleware

Options

1.types:it can be a action type,or action create function.

  requestType: before request,it is optional
  successType: request success,it is necessary.
  failureType: request fail,it is optional.

2.endPoint : request url

3.options : request option

4.checkStatusFn : A function to check your respond result,it is optional.

5.deaultMsg : A default message for error status.

6.failCallback : A function, you can deal the status of error responses,it is optional.

How to use

First,to enable Redux MIddleware,use applyMiddleware():

import { createStore, applyMiddleware } from 'redux';
import apiMiddleware from 'call-api-middleware';
import rootReducer from './reducers/index';

// create a store that has call-api-middleware middleware enabled
const createStoreWithMiddleware = applyMiddleware(
  apiMiddleware
)(createStore);

const store = createStoreWithMiddleware(rootReducer);
Then,you can add network request in your action files like this:
export function rulelist(type){
  let url = `${BASEURL}rule/rulelist`

  return {
    types: {successType:_rulelist,failureType:alertShow},
    endPoint: url,
    options: {credentials: 'include'},
    checkStatusFn: checkStatus,
    deaultMsg: "获取用车权限列表接口出错",
  }
}

call-api-middleware's People

Contributors

zhixunqiu avatar

Watchers

James Cloos avatar  avatar

Forkers

river209

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.