diff --git a/Cargo.toml b/Cargo.toml index a0be3ae..8915943 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,3 +6,4 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +actix-web = "4" diff --git a/src/main.rs b/src/main.rs index e7a11a9..f3f7914 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,28 @@ -fn main() { - println!("Hello, world!"); +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 }