mirror of
https://github.com/tokio-rs/axum.git
synced 2024-11-22 07:08:16 +01:00
9fbababc3a
* Handle errors in websocket example * Make it clear how to run all examples
28 lines
606 B
Rust
28 lines
606 B
Rust
//! Run with
|
|
//!
|
|
//! ```not_rust
|
|
//! cargo run --example hello_world
|
|
//! ```
|
|
|
|
use axum::prelude::*;
|
|
use std::net::SocketAddr;
|
|
|
|
#[tokio::main]
|
|
async fn main() {
|
|
tracing_subscriber::fmt::init();
|
|
|
|
// build our application with a route
|
|
let app = route("/", get(handler));
|
|
|
|
// run it
|
|
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
|
|
tracing::debug!("listening on {}", addr);
|
|
hyper::Server::bind(&addr)
|
|
.serve(app.into_make_service())
|
|
.await
|
|
.unwrap();
|
|
}
|
|
|
|
async fn handler() -> response::Html<&'static str> {
|
|
response::Html("<h1>Hello, World!</h1>")
|
|
}
|