tangenx / middleware

Modern middleware for Dart

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Middleware on Future for Dart and Flutter

Inspired by TypeScript version of middleware by negezor

Features

  • Working with async/await
  • Zero dependencies

Usage

import 'package:middleware/middleware.dart';

class Context {
  DateTime now;
}

final composedMiddleware = compose<Context>([
  (context, next) async {
    // Step 1

    await next();

    // Step 4

    // Print the current date from the next middleware
    print(context.now);
  },
  (context, next) async {
    // Step 2

    context.now = DateTime.now();

    await next();

    // Step 3
  }
]);
void main() async {
  var context = Context();

  composedMiddleware(
    context,
    () async {/* Last handler (next) */},
  ).then((what) {
    print('Middleware finished work');
  }).catchError(print);
}

Features and bugs

Please file feature requests and bugs at the issue tracker.

About

Modern middleware for Dart

License:MIT License


Languages

Language:Dart 100.0%