Function axum_server::bind [−][src]
pub fn bind(addr: SocketAddr) -> Server
Expand description
Create a Server
that will bind to provided address.
Examples found in repository
More examples
examples/configure_http.rs (line 21)
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
fn main() {
let app = Router::new().route("/", get(|| async { "Hello, world!" }));
let config = HttpConfig::new()
.http1_only(true)
.http2_only(false)
.max_buf_size(8192)
.build();
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
println!("listening on {}", addr);
axum_server::bind(addr)
.http_config(config)
.serve(app.into_make_service())
.await
.unwrap();
}
examples/shutdown.rs (line 23)
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
fn main() {
let app = Router::new().route("/", get(|| async { "Hello, world!" }));
let handle = Handle::new();
// Spawn a task to shutdown server.
tokio::spawn(shutdown(handle.clone()));
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
println!("listening on {}", addr);
axum_server::bind(addr)
.handle(handle)
.serve(app.into_make_service())
.await
.unwrap();
println!("server is shut down");
}
examples/graceful_shutdown.rs (line 26)
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
fn main() {
let app = Router::new().route("/", get(|| async { "Hello, world!" }));
let handle = Handle::new();
// Spawn a task to gracefully shutdown server.
tokio::spawn(graceful_shutdown(handle.clone()));
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
println!("listening on {}", addr);
axum_server::bind(addr)
.handle(handle)
.serve(app.into_make_service())
.await
.unwrap();
println!("server is shut down");
}