bind

Function bind 

Source
pub fn bind<A: Address>(addr: A) -> Server<A>
Expand description

Create a Server that will bind to provided address.

Examples found in repository?
examples/multiple_addresses.rs (line 21)
18async fn start_server(addr: SocketAddr) {
19    let app = Router::new().route("/", get(|| async { "Hello, world!" }));
20
21    axum_server::bind(addr)
22        .serve(app.into_make_service())
23        .await
24        .unwrap();
25}
More examples
Hide additional examples
examples/remote_address.rs (line 16)
9async fn main() {
10    let app = Router::new()
11        .route("/", get(handler))
12        .into_make_service_with_connect_info::<SocketAddr>();
13
14    let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
15
16    axum_server::bind(addr).serve(app).await.unwrap();
17}
examples/http_and_https.rs (line 24)
19async fn http_server() {
20    let app = Router::new().route("/", get(http_handler));
21
22    let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
23    println!("http listening on {}", addr);
24    axum_server::bind(addr)
25        .serve(app.into_make_service())
26        .await
27        .unwrap();
28}
examples/hello_world.rs (line 14)
9async fn main() {
10    let app = Router::new().route("/", get(|| async { "Hello, world!" }));
11
12    let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
13    println!("listening on {}", addr);
14    axum_server::bind(addr)
15        .serve(app.into_make_service())
16        .await
17        .unwrap();
18}
examples/hello_world_unix.rs (line 14)
9async fn main() {
10    let app = Router::new().route("/", get(|| async { "Hello, world!" }));
11
12    let addr = SocketAddr::from_pathname("/tmp/axum-server.sock").unwrap();
13    println!("listening on {}", addr.as_pathname().unwrap().display());
14    axum_server::bind(addr)
15        .serve(app.into_make_service())
16        .await
17        .unwrap();
18}
examples/shutdown.rs (line 23)
13async fn main() {
14    let app = Router::new().route("/", get(|| async { "Hello, world!" }));
15
16    let handle = Handle::new();
17
18    // Spawn a task to shutdown server.
19    tokio::spawn(shutdown(handle.clone()));
20
21    let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
22    println!("listening on {}", addr);
23    axum_server::bind(addr)
24        .handle(handle)
25        .serve(app.into_make_service())
26        .await
27        .unwrap();
28
29    println!("server is shut down");
30}