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.

roux #

Pub Version Test

Lightweight, fast router for Dart with static, parameterized, and wildcard route matching.

Install #

dart pub add roux

With Flutter:

flutter pub add roux

Quick Start #

import 'package:roux/roux.dart';

final router = createRouter<String>();

addRoute(router, 'GET', '/users', 'users');
addRoute(router, 'GET', '/users/:id', 'user');
addRoute(router, 'POST', '/users', 'create-user');
addRoute(router, null, '/health', 'any-method');

final match = findRoute(router, 'GET', '/users/123');
print(match?.data);   // user
print(match?.params); // {id: 123}

final all = findAllRoutes(router, 'GET', '/users/123');
for (final m in all) {
  print(m.data);
}

Route Syntax #

  • Static: /users
  • Named param: /users/:id
  • Embedded params: /files/:name.:ext
  • Single-segment wildcard: * (unnamed, captured as _0, _1, ...)
  • Multi-segment wildcard: ** (unnamed, captured as _) or **:path (named)
  • ** can match an empty remainder; **:name requires at least one segment.
  • Escape literal tokens with \\: /static\\:path/\\*/\\*\\* matches /static%3Apath/*/**
  • Paths are normalized to start with /.
  • Methods are case-insensitive. null uses the any-method token.

Matching Order #

  • Static > param > wildcard.
  • Method matching tries the requested method first, then the any-method token.

Options #

final router = createRouter<String>(
  caseSensitive: false,
  anyMethodToken: 'any',
);

Examples #

Any-method route #

addRoute(router, null, '/status', 'ok');

Find all matches #

final matches = findAllRoutes(router, 'GET', '/files/report.pdf');
for (final m in matches) {
  print(m.data);
}

Convert a pattern to RegExp #

final re = routeToRegExp('/users/:id');

License #

MIT. See LICENSE.

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