| Crates.io | turnstile-actix-web |
| lib.rs | turnstile-actix-web |
| version | 0.1.1 |
| created_at | 2025-03-30 20:18:59.821769+00 |
| updated_at | 2025-03-30 21:55:50.737454+00 |
| description | Cloudflare Turnstile Middleware for Actix Web |
| homepage | |
| repository | https://github.com/Leaf48/Turnstile-Rust |
| max_upload_size | |
| id | 1612720 |
| size | 70,217 |
Middleware for Actix Web
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
}