Last active
February 12, 2022 23:46
-
-
Save AndyWatt83/7c9e6cbacaf0b047e7e11fbc1effb9f9 to your computer and use it in GitHub Desktop.
Very simple Actix API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use actix_web::{middleware, web, App, HttpRequest, HttpServer}; | |
async fn say_hello(req: HttpRequest) -> &'static str { | |
println!("REQ: {:?}", req); | |
"Hello world!" | |
} | |
#[actix_web::main] | |
async fn main() -> std::io::Result<()> { | |
std::env::set_var("RUST_LOG", "actix_web=info"); | |
env_logger::init(); | |
HttpServer::new(|| { | |
App::new() | |
// enable logger | |
.wrap(middleware::Logger::default()) | |
.service(web::resource("/").to(say_hello)) | |
}) | |
.bind("127.0.0.1:8080")? | |
.run() | |
.await | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment