axum/examples
David Pedersen f67abd1ee2
Add extractor for remote connection info (#55)
Fixes https://github.com/tokio-rs/axum/issues/43

With this you can get the remote address like so:

```rust
use axum::{prelude::*, extract::ConnectInfo};
use std::net::SocketAddr;

let app = route("/", get(handler));

async fn handler(ConnectInfo(addr): ConnectInfo<SocketAddr>) -> String {
    format!("Hello {}", addr)
}

// Starting the app with `into_make_service_with_connect_info` is required
// for `ConnectInfo` to work.
let make_svc = app.into_make_service_with_connect_info::<SocketAddr, _>();

hyper::Server::bind(&"0.0.0.0:3000".parse().unwrap())
    .serve(make_svc)
    .await
    .expect("server failed");
```

This API is fully generic and supports whatever transport layer you're using with Hyper. I've updated the unix domain socket example to extract `peer_creds` and `peer_addr`.
2021-07-31 21:36:30 +02:00
..
templates Add HTML template example (#17) 2021-06-13 13:58:12 +02:00
websocket Add support for websockets (#3) 2021-06-12 20:50:30 +02:00
error_handling_and_dependency_injection.rs Rename to axum (#28) 2021-07-09 21:36:14 +02:00
form.rs Rename to axum (#28) 2021-07-09 21:36:14 +02:00
hello_world.rs Rename to axum (#28) 2021-07-09 21:36:14 +02:00
key_value_store.rs Docs improvements (#37) 2021-07-22 15:00:33 +02:00
multipart_form.rs Add Multipart extractor for consuming multipart/form-data requests (#32) 2021-07-14 16:53:37 +02:00
README.md Add unix domain socket example (#53) 2021-07-31 12:22:38 +02:00
static_file_server.rs Misc clean up 2021-07-22 21:12:29 +02:00
templates.rs Rename to axum (#28) 2021-07-09 21:36:14 +02:00
testing.rs Add testing example with real HTTP server 2021-07-22 21:12:40 +02:00
todos.rs Add todos example (#38) 2021-07-22 15:38:32 +02:00
tokio_postgres.rs Rename to axum (#28) 2021-07-09 21:36:14 +02:00
unix_domain_socket.rs Add extractor for remote connection info (#55) 2021-07-31 21:36:30 +02:00
versioning.rs Make extractors easier to write (#36) 2021-07-22 13:23:50 +02:00
websocket.rs Make websocket handlers support extractors (#41) 2021-07-30 15:19:53 +02:00

Examples