Skip to content

Instantly share code, notes, and snippets.

@AndyWatt83
Last active February 12, 2022 23:46
Show Gist options
  • Save AndyWatt83/7c9e6cbacaf0b047e7e11fbc1effb9f9 to your computer and use it in GitHub Desktop.
Save AndyWatt83/7c9e6cbacaf0b047e7e11fbc1effb9f9 to your computer and use it in GitHub Desktop.
Very simple Actix API
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