Skip to content
pubscout

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.

WASM-readyRock solid
$ flutter pub add shelf_router
Source repository

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.

  • dart_frog_cli

    Official command-line interface for the Dart Frog backend framework.

  • flint_dart

    Full‑stack Dart framework for building server, UI, and APIs in pure Dart

  • vania

    A fast backend framework for Dart with routing, ORM, migrations, and middleware.

Works with

Packages commonly used together with shelf_router: ones it builds on, ones built on it, and its own family.