Skip to content
pubscout

shelf

1.4.3, released 5 weeks ago by tools.dart.dev

Composable web server middleware for Dart

WASM-readyRock solid
$ flutter pub add shelf
Source repository

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.

Works with

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