Add actix-web

This commit is contained in:
William Brawner 2023-10-18 19:48:49 -06:00
parent 04802434fd
commit 6bbb421167
Signed by: wbrawner
GPG key ID: 8FF12381C6C90D35
3 changed files with 1235 additions and 2 deletions

1218
Cargo.lock generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -6,3 +6,4 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
actix-web = "4"

View file

@ -1,3 +1,17 @@
fn main() { use std::env;
println!("Hello, world!");
use actix_web::{web, App, HttpResponse, HttpServer, Responder};
async fn pong() -> impl Responder {
HttpResponse::Ok().body("PONG")
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
let port: u16 = env::var("PORT").map_or(8080, |p| p.parse::<u16>().unwrap_or(8080));
HttpServer::new(|| App::new().route("/ping", web::get().to(pong)))
.bind(("0.0.0.0", port))?
.run()
.await
} }