Tutorial6 min read
Deploy a Rust Actix Web Server with OpenClaw
Maximum performance Rust deployment. Actix-web with async/await and minimal resource usage.
Rust with Actix-web gives you maximum performance for OpenClaw. Here's how to deploy.
The Actix Web Server
// src/main.rs
use actix_web::{web, App, HttpServer, HttpResponse, Responder};
use serde::Deserialize;
#[derive(Deserialize)]
struct ChatRequest {
message: String,
}
async fn health() -> impl Responder {
HttpResponse::Ok().json(serde_json::json!({
"status": "ok"
}))
}
async fn chat(req: web::Json<ChatRequest>) -> impl Responder {
let response = openclaw::chat(&req.message).await;
HttpResponse::Ok().json(serde_json::json!({
"response": response
}))
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| {
App::new()
.route("/health", web::get().to(health))
.route("/chat", web::post().to(chat))
})
.bind(("0.0.0.0", 8080))?
.run()
.await
}
Cargo.toml
[dependencies]
actix-web = "4"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
openclaw-sdk = "0.1"
Build and Deploy
cargo build --release
fly launch --no-deploy
fly secrets set OPENAI_API_KEY=sk-...
fly deploy