Skip to content
pubscout

shelf_router_generator

1.1.5, released 5 months ago by tools.dart.dev

Generate request routers for the shelf web-framework using source annotations.

$ flutter pub add shelf_router_generator
Source repository

What it does

It provides a builder compatible with package:build that automatically generates request routers for the Shelf web framework based on annotations in code. It allows developers to define routes cleanly inside service classes rather than manually wiring handlers together.

AI-written summary of version 1.1.5, based on the package's README and metadata. Report an inaccuracy

Use it when

  • Building web applications or servers using the shelf framework
  • You prefer annotation-driven route generation over manual configuration

Skip it when

  • Not using the shelf web framework
  • You prefer manual router configuration without build_runner steps

Strengths

  • Keeps routing logic organized inside respective service classes
  • Integrates seamlessly with build_runner and source_gen

Weaknesses

  • Requires running a build step via build_runner
  • Adds code generation boilerplate to the project

Setup

Kind
Pure Dart
Effort
Low
Code generation
Yes (build_runner)
Direct dependencies
8

Add shelf_router_generator and build_runner to dev_dependencies, then run build_runner to generate routing code.

class UserService {
  @Route.get('/users/')
  Future<Response> listUsers(Request request) async {
    return Response.ok('["user1"]');
  }

  Router get router => _$UserServiceRouter(this);
}

Alternatives

Packages that do the same job and could replace shelf_router_generator.

  • copy_with_extension

    Annotation for generating copyWith extensions code using copy_with_extension_gen.

  • build_cli

    Parse command line arguments directly into an annotation class using build_runner or a standalone CLI.

  • widgetbook_annotation

    Annotations for widgetbook_generator to build Flutter widgets in isolation.

  • masamune

    A Flutter framework that uses code generation to scaffold apps with built‑in state, routing, forms and theming.

Works with

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