Skip to content

Commit

Permalink
examples: Migrate axum-key-value-store to hyper 1
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliboy50 authored Jan 13, 2024
1 parent 833bec4 commit ed963f1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
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
*/

0 comments on commit ed963f1

Please sign in to comment.