axum/examples/hello_world.rs

21 lines
490 B
Rust
Raw Normal View History

2021-07-09 21:36:14 +02:00
use axum::prelude::*;
2021-05-31 10:20:07 +02:00
use std::net::SocketAddr;
#[tokio::main]
async fn main() {
// build our application with a route
let app = route("/", get(handler));
2021-05-31 10:20:07 +02:00
// run it
2021-05-31 10:20:07 +02:00
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
tracing::debug!("listening on {}", addr);
2021-06-19 12:50:33 +02:00
hyper::Server::bind(&addr)
.serve(app.into_make_service())
.await
.unwrap();
2021-05-31 10:20:07 +02:00
}
2021-06-09 09:03:09 +02:00
async fn handler() -> response::Html<&'static str> {
2021-06-04 01:00:48 +02:00
response::Html("<h1>Hello, World!</h1>")
2021-05-31 10:20:07 +02:00
}