Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(example): migrate axum-key-value-store to axum 0.7 #448

Merged
merged 1 commit into from
Jan 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions examples/axum-key-value-store/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ publish = false
license = "MIT"

[dependencies]
hyper = { version = "0.14.15", features = ["full"] }
tokio = { version = "1.2.0", features = ["full"] }
tokio = { version = "1.32.0", features = ["full"] }
tower = { version = "0.4.13", features = ["full"] }
tower-http = { path = "../../tower-http", features = ["full"] }
tracing = "0.1"
tracing-subscriber = { version = "0.3.11", features = ["env-filter"] }
axum = "0.6"
clap = { version = "4.3.16", features = ["derive"] }
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
axum = "0.7"
clap = { version = "4.4.4", features = ["derive"] }
19 changes: 7 additions & 12 deletions examples/axum-key-value-store/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
fn main() {
eprintln!("this example has not yet been updated to hyper 1.0");
}

/*
use axum::{
body::Bytes,
extract::{Path, State},
Expand All @@ -18,6 +13,7 @@ use std::{
sync::{Arc, RwLock},
time::Duration,
};
use tokio::net::TcpListener;
use tower::ServiceBuilder;
use tower_http::{
timeout::TimeoutLayer,
Expand Down Expand Up @@ -49,10 +45,12 @@ async fn main() {
// Run our service
let addr = SocketAddr::from((Ipv4Addr::UNSPECIFIED, config.port));
tracing::info!("Listening on {}", addr);
axum::Server::bind(&addr)
.serve(app().into_make_service())
.await
.expect("server error");
axum::serve(
TcpListener::bind(addr).await.expect("bind error"),
app().into_make_service(),
)
.await
.expect("server error");
}

fn app() -> Router {
Expand All @@ -79,8 +77,6 @@ fn app() -> Router {
.sensitive_response_headers(sensitive_headers)
// Set a timeout
.layer(TimeoutLayer::new(Duration::from_secs(10)))
// Box the response body so it implements `Default` which is required by axum
.map_response_body(axum::body::boxed)
// Compress responses
.compression()
// Set a `Content-Type` if there isn't one already.
Expand Down Expand Up @@ -113,4 +109,3 @@ async fn set_key(Path(path): Path<String>, state: State<AppState>, value: Bytes)

// See https://github.com/tokio-rs/axum/blob/main/examples/testing/src/main.rs for an example of
// how to test axum apps
*/