# rusd **Repository Path**: jonnyjiang/rusd ## Basic Information - **Project Name**: rusd - **Description**: 基于rust实现DDD - **Primary Language**: Rust - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-04-13 - **Last Updated**: 2024-04-13 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 准备工作 ## 依赖 ```toml [dependencies] actix-web = "4.5.1" ``` ## 启动类 ```rust #[actix_web::main] async fn main() -> std::io::Result<()>{ let server = HttpServer::new(|| { App::new() .service(hello) .service(echo) .route("/hey", web::get().to(manual_hello)) }) .bind(("127.0.0.1", 8080))? .run(); println!("started on http://127.0.0.1:8080"); server.await } ``` ## 注册handler ```rust #[get("/")] async fn hello() -> impl Responder { HttpResponse::Ok().body("Hello world!") } #[post("/echo")] async fn echo(req_body: String) -> impl Responder { HttpResponse::Ok().body(req_body) } ``` ## 注册handler到Server ### App::service ```rust App::new().service(hello); ``` ### route ```rust App::new() .route("/hey", web::get().to(manual_hello)) ```