routed 0.3.2 copy "routed: ^0.3.2" to clipboard
routed: ^0.3.2 copied to clipboard

A modular HTTP engine and routing framework for Dart with middleware, configuration, sessions, and observability built in.

routed #

Pub Version CI License Sponsor

routed is a modular HTTP engine for Dart with first-class routing, middleware, configuration, localization, logging, signals, and lifecycle management. It is the foundation of the routed ecosystem packages published from this repo.

Highlights #

  • Declarative routing with strongly typed handlers, middleware stacks, and lifecycle events (including WebSocket routes).
  • Provider architecture for configuration, caching, storage, sessions, localization, rate limiting, and more.
  • Observability tooling via contextual logging, signal hubs, and event-publishing hooks for instrumentation.
  • Extensible drivers so you can register custom storage/cache/session drivers that plug directly into the CLI helper commands.

Install #

dependencies:
  routed: ^0.2.0

Then run dart pub get.

Quick start #

import 'package:routed/routed.dart';

Future<void> main() async {
  final engine = await Engine.createFull();
  engine
    ..get('/', (ctx) => ctx.text('Hello routed!'))
    ..get('/json', (ctx) => ctx.json({'ok': true}))
    ..group('/api', (router) {
      router.post('/users', (ctx) async {
        final body = await ctx.jsonBody();
        return ctx.json({'name': body['name'], 'created': true});
      });
    });

  await engine.serve(host: '127.0.0.1', port: 8080);
}

Auth #

Use package:routed/auth.dart for auth providers, routes, and middleware.

import 'package:routed/auth.dart';
import 'package:routed/routed.dart';

Future<void> main() async {
  final engine = await Engine.createFull();
  engine.container.instance<AuthOptions>(
    AuthOptions(
      providers: [
        CredentialsProvider(
          authorize: (ctx, provider, credentials) async {
            if (credentials.password == 'secret') {
              return AuthUser(id: 'user-1', email: credentials.email);
            }
            return null;
          },
        ),
      ],
      sessionStrategy: AuthSessionStrategy.session,
    ),
  );

  await engine.serve(host: '127.0.0.1', port: 8080);
}

Coverage #

Latest local coverage: 61.9% line coverage.

dart test --coverage=coverage
dart pub run coverage:format_coverage --lcov --in=coverage --out=coverage/lcov.info --package=. --report-on=lib

Cli tooling #

Routed provides cli tooling Command-line tooling for the Routed framework. It scaffolds projects, manages providers and middleware, generates configuration defaults, and offers helpers for local dev workflows.

Highlights #

  • Scaffolding templates for API, web, and full-stack apps with matching tests and env files.
  • Config generation powered by Routed’s provider snapshots, so stubs always match the latest defaults.
  • Provider + middleware management including manifest edits and config doc rendering.
  • Developer ergonomics such as the dev command for restart loops and tooling that mirrors the production CLI.

Add the executable to your dev_dependencies and invoke it via dart run. Prefer the global install (dart pub global activate routed) when you want the routed command everywhere.

Commands #

  • routed create <name> – scaffold API/web/fullstack templates with env files and starter tests.
  • routed config:init – write config stubs using Routed’s provider defaults.
  • routed provider:list --config – inspect enabled providers and their config docs.
  • routed dev – run the development server with auto-restart hooks.

Example #

dart run routed create demo_api --template api
cd demo_api
dart run routed config:init
dart run routed dev

See lib/src/args/commands and the tests under test/ for more examples.

Browse the /doc directory for deeper topics (drivers, events, configuration) or open the docs published at docs.routed.dev.

Funding #

Help keep the ecosystem maintained by buying me a coffee.

0
likes
140
points
248
downloads

Publisher

unverified uploader

Weekly Downloads

A modular HTTP engine and routing framework for Dart with middleware, configuration, sessions, and observability built in.

Repository (GitHub)
View/report issues

Documentation

API reference

Funding

Consider supporting this project:

www.buymeacoffee.com

License

MIT (license)

Dependencies

acanthis, analyzer, args, build, collection, contextual, dartastic_opentelemetry, dartastic_opentelemetry_api, decimal, dotenv, es_compression, event_bus, file, file_cloud, fuzzywuzzy, glob, http, http2, http_parser, image, intl, jose, json2yaml, json_annotation, json_schema_builder, liquify, meta, mime, mustache_template, path, pointycastle, redis, sentry, shelf, stack_trace, storage_fs, stream_transform, timezone, uuid, watcher, xml, yaml

More

Packages that depend on routed