turnstile-actix-web

Crates.ioturnstile-actix-web
lib.rsturnstile-actix-web
version0.1.1
created_at2025-03-30 20:18:59.821769+00
updated_at2025-03-30 21:55:50.737454+00
descriptionCloudflare Turnstile Middleware for Actix Web
homepage
repositoryhttps://github.com/Leaf48/Turnstile-Rust
max_upload_size
id1612720
size70,217
wa (Leaf48)

documentation

README

Turnstile-Rust

Middleware for Actix Web

Usage

Import and initialize the middleware in your Actix Web application as shown below:

use actix_web::{web, App, HttpResponse, HttpServer};
use actix_turnstile::{Turnstile, TurnstileConfig};

#[actix_web::main]
async fn main() -> std::io::Result<()> {
    // Initialize the Turnstile configuration with your Cloudflare secret key.
    let turnstile_config = TurnstileConfig::new("your_secret_key_here");

    // Build the Actix Web server.
    HttpServer::new(move || {
        App::new()
            // Register the Turnstile middleware.
            .wrap(Turnstile::new(turnstile_config.clone()))
            // Define your routes.
            .service(
                web::resource("/")
                    .to(|| async { HttpResponse::Ok().body("This route is protected by Cloudflare Turnstile") }),
            )
    })
    .bind("127.0.0.1:8080")?
    .run()
    .await
}
Commit count: 6

cargo fmt