Skip to content
pubscout

shelf_limiter

2.0.1, released 2 years ago by weaverlabs.ca

Rate limiting middleware for the Shelf web framework in Dart.

WASM-ready
$ flutter pub add shelf_limiter
Source repository

What it does

shelf_limiter is a customizable rate limiting middleware for the Shelf library. It allows developers to control request rates globally or configure different limits per endpoint using wildcard path matching.

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

Use it when

  • You are building a Dart backend using the Shelf library and need to protect APIs from abuse.
  • You require customizable rate limits with support for endpoint-specific rules and custom headers.

Skip it when

  • You are not using the Shelf library for your Dart backend.
  • You need distributed rate limiting across multiple server instances (the package manages state in-memory).

Strengths

  • Supports endpoint-specific limits and wildcard path matching like `/api/v1/*`.
  • Allows customizing rate-limit-exceeded responses and adding custom response headers.
  • Easy integration into existing Shelf middleware pipelines.

Weaknesses

  • Lacks documented distributed storage backend support for multi-instance deployments out of the box.

Setup

Kind
Pure Dart
Effort
Low
Code generation
No
Direct dependencies
1
import 'package:shelf/shelf.dart';
import 'package:shelf/shelf_io.dart' as io;
import 'package:shelf_limiter/shelf_limiter.dart';

void main() async {
  final limiter = shelfLimiter(
    RateLimiterOptions(
      maxRequests: 5,
      windowSize: const Duration(minutes: 1),
    ),
  );

  final handler =
      const Pipeline().addMiddleware(limiter).addHandler(_echoRequest);

  var server = await io.serve(handler, 'localhost', 8080);
  print('Server listening on port ${server.port}');
}

Response _echoRequest(Request request) => Response.ok('Request received');

Alternatives

Packages that do the same job and could replace shelf_limiter.

  • shelf_proxy

    A shelf handler for proxying HTTP requests to another server.

  • shelf_router

    A request router for the shelf web-framework with support for URL parameters and nested routers.

  • dart_frog

    A minimalistic Dart backend framework with a built‑in dev server and Docker support.

Works with

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