Skip to content
pubscout

shelf_packages_handler

3.0.2, released 4 years ago by tools.dart.dev

Shelf handler that serves a `packages/` directory of Dart package assets.

Quiet but busy
$ flutter pub add shelf_packages_handler
Source repository

What it does

Provides a Shelf handler that resolves `package:` URIs and serves the corresponding files from a `packages/` directory. Designed to be placed first in a Cascade so other requests fall through to subsequent handlers.

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

Use it when

  • You need to serve Dart package assets over HTTP during development
  • You are building a simple Shelf server and want automatic package resolution
  • You want a drop‑in handler that works with Shelf's Cascade

Skip it when

  • You require a full‑featured static file server with caching and compression
  • You need to serve assets from locations other than `packages/`
  • You are deploying to production where a CDN is preferred

Strengths

  • Very small and focused API
  • Integrates directly with Shelf's Cascade
  • Null‑safe and requires only core Shelf dependencies

Weaknesses

  • Only serves `packages/` paths, no other static file features
  • No built‑in caching or performance optimizations

Setup

Kind
Pure Dart
Effort
Low
Code generation
No
Direct dependencies
3
import 'package:shelf/shelf.dart';
import 'package:shelf_packages_handler/shelf_packages_handler.dart';

final handler = packagesHandler({
  'my_package': Uri.parse('file:///path/to/my_package/lib/'),
});
final cascade = Cascade().add(handler).add(_otherHandler).handler;

Works with

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