spanner 1.0.1 copy "spanner: ^1.0.1" to clipboard
spanner: ^1.0.1 copied to clipboard

Generic HTTP Router implementation, internally uses a Radix Tree (aka compact Prefix Tree), supports route params, wildcards.

spanner 🎢 #

Generic HTTP Router implementation, internally uses a Radix Tree (aka compact Prefix Tree), supports route params, wildcards.

import 'package:spanner/spanner.dart';

void main() {
  final spanner = Spanner();

  List<String> getUsers() => ['Foo', 'Bar'];

  String getUser(String userId) => 'Hello $userId';

  spanner.addRoute(HTTPMethod.GET, '/', getUsers);

  spanner.addRoute(HTTPMethod.GET, '/<userId>', getUser);

  final result = spanner.lookup(HTTPMethod.GET, '/');
  if (result == null) return;
  

  /// This contains all parameters that were resolved in the route
  final routeParams = result.params; // Map<String, dynamic>

  /// your handler will be in this list.
  ///
  /// If any middlewares where resolved along the route to this handler
  /// they'll be present in the list
  ///
  /// The list is ordered in the exact way you registed your middlewares and handlers
  final resolvedHandler = result.values; // List<dynamic>
}

3
likes
0
pub points
34%
popularity

Publisher

verified publisheryaroo.dev

Generic HTTP Router implementation, internally uses a Radix Tree (aka compact Prefix Tree), supports route params, wildcards.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

collection, equatable, meta

More

Packages that depend on spanner