diff --git a/Cargo.toml b/Cargo.toml index e3feac8..28fb1bc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,4 +5,5 @@ edition = "2024" [dependencies] actix = "0.13" -tokio = { version = "1.44", features = ["full"] } +actix-web = "4.10" +#tokio = { version = "1.44", features = ["full"] } maybe diff --git a/src/main.rs b/src/main.rs index 51e6166..f3f7914 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,28 @@ -#[tokio::main] -async fn main() -> Result<(), Box> { - println!("Hello, world!"); - Ok(()) +use actix_web::{get, post, web, App, HttpResponse, HttpServer, Responder}; + +#[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) +} + +async fn manual_hello() -> impl Responder { + HttpResponse::Ok().body("Hey there!") +} + +#[actix_web::main] +async fn main() -> std::io::Result<()> { + HttpServer::new(|| { + App::new() + .service(hello) + .service(echo) + .route("/hey", web::get().to(manual_hello)) + }) + .bind(("127.0.0.1", 8080))? + .run() + .await }