roux 0.1.1 copy "roux: ^0.1.1" to clipboard
roux: ^0.1.1 copied to clipboard

A lightweight, fast, functional router for Dart with static, parameterized, and wildcard route matching.

example/main.dart

import 'package:roux/roux.dart';

void main() {
  final router = createRouter<String>(caseSensitive: false);

  addRoute(router, 'GET', '/users', 'listUsers');
  addRoute(router, 'GET', '/users/:id', 'getUser');
  addRoute(router, 'GET', '/files/:name.:ext', 'getFile');
  addRoute(router, null, '/health', 'healthCheck');
  addRoute(router, 'GET', '/assets/**:path', 'assetLookup');
  addRoute(router, 'GET', '/docs/*', 'docsWildcard');

  describe(router, 'GET', '/users');
  describe(router, 'GET', '/users/42');
  describe(router, 'GET', '/files/report.pdf');
  describe(router, 'POST', '/health');
  describe(router, 'GET', '/assets/images/logo.png');
  describe(router, 'GET', '/docs/getting-started');
  describe(router, 'GET', '/missing');
}

void describe(RouterContext<String> router, String? method, String path) {
  final match = findRoute(router, method, path);
  if (match == null) {
    print('[${method ?? 'ANY'}] $path -> no match');
    return;
  }

  final params = match.params == null ? '' : ' params=${match.params}';
  print('[${method ?? 'ANY'}] $path -> ${match.data}$params');
}
0
likes
160
points
49
downloads

Publisher

verified publishermedz.dev

Weekly Downloads

A lightweight, fast, functional router for Dart with static, parameterized, and wildcard route matching.

Repository (GitHub)
View/report issues

Topics

#router #http #path-matching #trie

Documentation

API reference

Funding

Consider supporting this project:

github.com

License

MIT (license)

More

Packages that depend on roux