redux_api_middleware 0.1.9

  • Readme
  • Changelog
  • Example
  • Installing
  • 74

redux_api_middleware #

Redux middleware for calling APIs.

The apiMiddleware intercepts and calls Redux Standard API-calling Actions (RSAAs), and dispatches Flux Standard Actions (FSAs) to the next middleware.

Redux Standard API-calling Actions #

The definition of a Redux Standard API-calling Action below is the one used to validate RSAA actions.

  • actions that are not instances of RSAA will be passed to the next middleware without any modifications;
  • actions that are instancesof RSAA that fail validation will result in an error request FSA.

A Redux Standard API-calling Action MUST

  • be a RSAA instance,

Flux Standard Actions #

For convenience, we recall here the definition of a Flux Standard Action.

An action MUST

  • be a RSAA instance,
  • have a type property.

An action MAY

  • have an error property,
  • have a payload property,
  • have a meta property.

Credits #

This lib is redux-api-middleware library simply adapted to Dart.

Changelog #

0.1.9 #

  • The failure request payload wasn't being processed.
  • Exported the errors for typed usage.

0.1.8 #

  • The wrong descriptor was being used in request error.
  • Renaming the descriptor for more clarity.

0.1.7 #

  • Export the FSA for a more typed reducer.

0.1.6 #

  • Export the FSA for a more typed reducer.

0.1.5 #

  • The request action was not getting dispatched. Fixed that

0.1.4 #

  • Now the payload is a string, ww let the user parse this string.

0.1.3 #

  • http package user lower cased content-type. Fixing that.

0.1.2 #

  • Improving analysis score.

0.1.0 #

  • Initial version, includes a apiMiddleware, which intercepts and calls functions that are dispatched to the Store.


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 :(';
        return state;

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

  // Create a `RSAA`.
  var rsaa = RSAA(
    method: 'GET',
    endpoint: '',
    types: [

  // Dispatch the action! The `apiMiddleware` will intercept and invoke
  // the action function. It will go to the reducer as an FSA.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  redux_api_middleware: ^0.1.9

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:redux_api_middleware/redux_api_middleware.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jan 16, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4

Health issues and suggestions

Document public APIs. (-1 points)

50 out of 50 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Format lib/src/middleware.dart.

Run dartfmt to format lib/src/middleware.dart.

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (redux).


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.2.0 <3.0.0
http ^0.12.0 0.12.0+4
meta >=1.0.0 <2.0.0 1.1.8
redux >=3.0.0 <4.0.0 3.0.0 4.0.0
Transitive dependencies
async 2.4.0
charcode 1.1.2
collection 1.14.12
http_parser 3.1.3
path 1.6.4
pedantic 1.9.0
source_span 1.6.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6