website-screenshot-actix-governor

Crates.iowebsite-screenshot-actix-governor
lib.rswebsite-screenshot-actix-governor
version0.3.0
sourcesrc
created_at2022-05-25 08:55:26.927273
updated_at2022-05-25 08:55:26.927273
descriptionA rate-limiting middleware for actix-web backed by the governor crate
homepage
repositoryhttps://github.com/devtomio/actix-governor
max_upload_size
id593357
size106,318
Tomio (devtomio)

documentation

README

CI Docs crates.io

Actix Governor

A middleware for actix-web that provides rate-limiting backed by governor.

Features:

  • Simple to use
  • High performance
  • Robust yet flexible API

Example

use actix_governor::{Governor, GovernorConfigBuilder};
use actix_web::{web, App, HttpServer, Responder};

async fn index() -> impl Responder {
    "Hello world!"
}

#[actix_web::main]
async fn main() -> std::io::Result<()> {
    // Allow bursts with up to five requests per IP address
    // and replenishes one element every two seconds
    let governor_conf = GovernorConfigBuilder::default()
        .per_second(2)
        .burst_size(5)
        .finish()
        .unwrap();

    HttpServer::new(move || {
        App::new()
            // Enable Governor middleware
            .wrap(Governor::new(&governor_conf))
            // Route hello world service
            .route("/", web::get().to(index))
    })
    .bind("127.0.0.1:8080")?
    .run()
    .await
}

Add this to your Cargo.toml:

[dependencies]
actix-governor = "0.3"
Commit count: 66

cargo fmt