shelf_router
1.1.5, released 5 weeks ago by tools.dart.dev
A request router for the shelf web-framework with support for URL parameters and nested routers.
What it does
It matches incoming HTTP requests to handlers using route patterns. It supports URL parameters, nested routers, and can be used with source annotations via shelf_router_generator.
AI-written summary of version 1.1.5, based on the package's README and metadata. Report an inaccuracy
Use it when
- You are building a web application or API in Dart using the shelf framework
- You need URL parameters and nested routing capabilities for your server
Skip it when
- You are building a client-side Flutter application UI and need screen navigation
- You are not using the shelf package for your backend
Strengths
- Convenient routing matching for shelf web applications
- Supports nested routers and URL parameters
- Prefix Trie filter optimization for static path segments
Weaknesses
- Limited to the shelf ecosystem
- Requires manual handler mapping unless using the separate generator package
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 3
Add shelf and shelf_router to your pubspec.yaml dependencies.
import 'package:shelf_router/shelf_router.dart';
import 'package:shelf/shelf.dart';
import 'package:shelf/shelf_io.dart' as io;
var router = Router();
router.get('/hello', (Request request) {
return Response.ok('hello-world');
});
router.get('/user/<user>', (Request request, String user) {
return Response.ok('hello $user');
});Alternatives
Packages that do the same job and could replace shelf_router.
- dart_frog
A minimalistic Dart backend framework with a built‑in dev server and Docker support.
80Compare - dart_frog_cli
Official command-line interface for the Dart Frog backend framework.
86Compare - flint_dart
Full‑stack Dart framework for building server, UI, and APIs in pure Dart
74Compare - vania
A fast backend framework for Dart with routing, ORM, migrations, and middleware.
71Compare
Works with
Packages commonly used together with shelf_router: ones it builds on, ones built on it, and its own family.
- shelfshelf_router depends on itComposable web server middleware for Dart
- http_methodsshelf_router depends on itProvides a list of IANA‑registered HTTP methods and helper functions to check them.
- shelf_staticSame familyServe static files over HTTP with the shelf package
- shelf_web_socketSame familyShelf handler that upgrades HTTP to WebSocket and provides a WebSocketChannel per connection.
- shelf_packages_handlerSame familyShelf handler that serves a `packages/` directory of Dart package assets.
- shelf_proxySame familyA shelf handler for proxying HTTP requests to another server.
- sseSame familyBidirectional Server Sent Events client and server for Dart.
- ddsSame familyLibrary to spawn and communicate with the Dart Developer Service (DDS) via HTTP, WebSocket, or SSE.