shelf
1.4.3, released 5 weeks ago by tools.dart.dev
Composable web server middleware for Dart
What it does
Shelf provides a simple, composable API for building HTTP servers and middleware. It lets you map request handlers to responses and chain middleware in a Pipeline.
AI-written summary of version 1.4.3, based on the package's README and metadata. Report an inaccuracy
Use it when
- Creating a lightweight HTTP server
- Composing reusable middleware
- Adding logging, auth, or compression to a server
Skip it when
- You need a full-featured web framework with routing, templating, and ORM
Strengths
- Easy composition via Pipeline
- Supports sync and async handlers
- Built-in utilities like logRequests and Response helpers
Weaknesses
- No built-in routing or templating
- Requires additional packages for static files or routing
- Not a full framework
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 6
import 'package:shelf/shelf.dart';
import 'package:shelf/shelf_io.dart' as shelf_io;
void main() async {
var handler = const Pipeline().addMiddleware(logRequests()).addHandler(_echoRequest);
var server = await shelf_io.serve(handler, 'localhost', 8080);
print('Serving at http://${server.address.host}:${server.port}');
}
Response _echoRequest(Request request) => Response.ok('Request for "${request.url}"');Alternatives
Packages that do the same job and could replace shelf.
- dart_frog_cli
Official command-line interface for the Dart Frog backend framework.
86Compare - relic_io
dart:io adapter for Relic web server.
81Compare - realtime_client
Dart client for Supabase Realtime, listening to PostgreSQL changes via WebSocket
89Compare - vania
A fast backend framework for Dart with routing, ORM, migrations, and middleware.
71Compare
Works with
Packages commonly used together with shelf: ones it builds on, ones built on it, and its own family.
- stack_traceshelf depends on itProvides parsing, inspection, and readable formatting of Dart stack traces.
- asyncshelf depends on itUtility classes and helpers that extend Dart's async library.
- http_parsershelf depends on itA platform-independent package for parsing and serializing HTTP formats.
- stream_channelshelf depends on itAn abstraction for two-way communication channels based on the Dart Stream class.
- poolSame familyManage a finite pool of resources to control concurrent operations.
- coverageSame familyCollects, manipulates, and formats code coverage data in Dart
- test_apiSame familyThe user facing API for structuring Dart tests and checking expectations.
- web_socket_channelSame familyCross‑platform WebSocket channel wrapper for Dart