[][src]Crate limitation_actix_middleware

An Actix web middleware for rate limiting requests using a fixed window counter keyed on a header.


Add limitation-actix-middleware to your Cargo.toml:

limitation-actix-middleware = "0.1.1"

Quick Example

The RateLimiter middleware is the primary type which is intended to be inserted in an Actix web app's middleware chain. The middleware requires 2 Data types to be present:

  1. A HeaderName which is the header to use as the rate limiter key
  2. A Limiter which performs the rate limiting and manages persistence
use actix_web::{http::header::HeaderName, web, App, HttpResponse};
use limitation_actix_middleware::{Limiter, RateLimiter};

// Choose a header to use for rate limit tracking
let header = web::Data::new(HeaderName::from_static("authorization"));
// Build a `Limiter` which will be used by the middleware
let limiter = web::Data::new(Limiter::build("redis://").finish()?);

let app = App::new()
    // Register the header as application data
    // Register the Limiter as application data
    // Insert the RateLimter middleware
            .route(web::get().to(|| HttpResponse::Ok()))
            .route(web::head().to(|| HttpResponse::MethodNotAllowed()))


This crate ships with an example program called catchall which can be run from the sources with:

$ cargo run --example catchall



A builder for a Limiter.


A rate limiter using a fixed window counter, backed by Redis.


Middleware for rate limiting requests using a fixed window counter keyed on a HeaaderName.


A report for a given key containing the limit status.



Error type for this crate.