redux_api_middleware 0.2.1 copy "redux_api_middleware: ^0.2.1" to clipboard
redux_api_middleware: ^0.2.1 copied to clipboard

A dart redux middleware for calling APIs. APIs interact with reducers made easy..

example/redux_api_middleware_example.dart

import 'package:redux/redux.dart';

import 'package:redux_api_middleware/redux_api_middleware.dart';

void main() {
  // First, create a quick reducer
  String reducer(String state, dynamic action) {
    switch (action['type']) {
      case 'request':
        return 'dispatched a request :)';
      case 'success':
        return 'dispatched a success :D';
      case 'failure':
        return 'dispatched a failure :(';
      default:
        return state;
    }
  }

  // Next, apply the `apiMiddleware` to the Store
  final store = Store<String>(
    reducer,
    middleware: [apiMiddleware],
  );

  // Create a `RSAA`.
  var action = {
    RSAA: {
      'method': 'GET',
      'endpoint': 'http://url.com/api/test',
      'types': [
        'request',
        'success',
        'failure',
      ],
    },
  };

  // Dispatch the action! The `apiMiddleware` will intercept and invoke
  // the action function. It will go to the reducer as an FSA.
  store.dispatch(action);
}
0
likes
30
pub points
11%
popularity

Publisher

unverified uploader

A dart redux middleware for calling APIs. APIs interact with reducers made easy..

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

http, meta, redux

More

Packages that depend on redux_api_middleware