redux_api_middleware 0.1.9

  • Readme
  • Changelog
  • Example
  • Installing
  • 54

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.

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 rsaa = 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(rsaa);
}

Use this package as a library

1. Depend on it

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


dependencies:
  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';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
13
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
54
Learn more about scoring.

We analyzed this package on Dec 7, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.6.1
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:redux_api_middleware/redux_api_middleware.dart.

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).

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.2.0 <3.0.0
http ^0.12.0 0.12.0+2
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.5.5
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6