shelf_static
1.2.0, released 5 weeks ago by tools.dart.dev
Serve static files over HTTP with the shelf package
What it does
shelf_static provides a Handler that serves files from a directory, supporting range requests, ETag and Cache‑Control headers. It replaces blocking IO with async calls for better concurrency.
AI-written summary of version 1.2.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- Building a simple web server or API that needs to serve static assets
- Prototyping or testing a shelf‑based application
- Serving documentation or public files in a Dart backend
Skip it when
- You need a highly optimized CDN‑style static file server with advanced caching or compression
- Your project already uses another static file server that integrates with your framework
Strengths
- Non‑blocking async file access
- Built‑in support for HTTP range, ETag, and Cache‑Control
- Easy integration with shelf middleware
- Responsive directory listing UI
Weaknesses
- Limited to the shelf ecosystem
- No built‑in HTTPS support (handled by shelf_io or other server)
- No advanced caching or compression features
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 5
Add shelf_static to pubspec, import, create a handler with createStaticHandler, and serve with shelf_io. No extra permissions or build_runner needed.
import 'package:shelf/shelf_io.dart' as io;
import 'package:shelf_static/shelf_static.dart';
void main() {
var handler = createStaticHandler('example/files', defaultDocument: 'index.html');
io.serve(handler, 'localhost', 8080);
}
Alternatives
Packages that do the same job and could replace shelf_static.
- relic
Lightweight web server framework inspired by Shelf, with typed APIs and a high‑performance native Zig adapter.
91Compare - ftp_server
Standards-compliant FTP and FTPS server implementation in Dart.
74Compare
Works with
Packages commonly used together with shelf_static: ones it builds on, ones built on it, and its own family.
- mimeshelf_static depends on itUtilities to resolve MIME types from file names, magic bytes, and to parse multipart streams.
- shelfshelf_static depends on itComposable web server middleware for Dart
- http_parsershelf_static depends on itA platform-independent package for parsing and serializing HTTP formats.
- convertshelf_static depends on itEncoders and decoders for converting between different data representations.
- shelf_web_socketSame familyShelf handler that upgrades HTTP to WebSocket and provides a WebSocketChannel per connection.
- shelf_proxySame familyA shelf handler for proxying HTTP requests to another server.
- sseSame familyBidirectional Server Sent Events client and server for Dart.
- dwdsSame familyProxies between the Chrome debug protocol and the Dart VM service protocol.