use actix_web::{web, App, HttpServer, HttpResponse, Responder};
use serde::{Deserialize, Serialize};
#[derive(Serialize)]
struct User { id: u32, name: String }
#[derive(Deserialize)]
struct Query { name: String }
async fn hello(query: web::Query<Query>) -> impl Responder {
HttpResponse::Ok().json(User {
id: 1,
name: query.name.clone(),
})
}
async fn health() -> impl Responder {
HttpResponse::Ok().body("سرور سالم است ✅")
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| {
App::new()
.route("/hello", web::get().to(hello))
.route("/health", web::get().to(health))
})
.bind("127.0.0.1:8080")?
.run()
.await
}
معرفی فریمورک بسیار سریع Actix-web و ساختار route handling و تزریق وابستگی در آن.