mirror of
https://github.com/tokio-rs/axum.git
synced 2024-12-28 23:38:20 +01:00
f67abd1ee2
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`. |
||
---|---|---|
.. | ||
templates | ||
websocket | ||
error_handling_and_dependency_injection.rs | ||
form.rs | ||
hello_world.rs | ||
key_value_store.rs | ||
multipart_form.rs | ||
README.md | ||
static_file_server.rs | ||
templates.rs | ||
testing.rs | ||
todos.rs | ||
tokio_postgres.rs | ||
unix_domain_socket.rs | ||
versioning.rs | ||
websocket.rs |
Examples
hello_world
- Very small getting started app.todos
- Provides a RESTful web server managing some Todos.key_value_store
- Slightly larger app with an in-memory key/value store.form
- Receiving data from an HTML<form>
.multipart_form
- How to parsemultipart/form-data
forms.static_file_server
- Serving static files from a directory. Could for example be the baseline for a single page app.templates
- Rending HTML templates using askama.testing
- How to test axum apps.versioning
- How one might version an API.websocket
- How to build an app that handles WebSocket connections.error_handling_and_dependency_injection
- How to handle errors and dependency injection using trait objects.tokio_postgres
- How to use a tokio-postgres and bb8 to query a database.unix_domain_socket
- How to run an Axum server over unix domain sockets.