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

fix(deps): update rust crate axum to 0.6.20 #7

Merged
merged 2 commits into from
Aug 23, 2023
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ name = "demo"
name = "echo"

[dependencies]
axum = { version = "0.6.0-rc.1", features = ["json"] }
axum = { version = "0.6.20", features = ["json"] }
clap = { version = "4", features = ["derive", "env"] }
once_cell = "1.18"
prometheus = "0.13"
Expand Down
6 changes: 3 additions & 3 deletions examples/demo/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// SPDX-License-Identifier: AGPL-3.0-or-later

use servus::axum::{
extract::{self, Extension},
extract::{self, State},
http::StatusCode,
response::IntoResponse,
routing::{get, post},
Expand Down Expand Up @@ -76,7 +76,7 @@ struct Message {
}

async fn post_message(
Extension(state): Extension<Arc<AppState>>,
State(state): State<Arc<AppState>>,
extract::Json(payload): extract::Json<Message>,
) -> StatusCode {
info!(
Expand All @@ -100,7 +100,7 @@ async fn post_message(
StatusCode::OK
}

async fn get_messages(Extension(state): Extension<Arc<AppState>>) -> impl IntoResponse {
async fn get_messages(State(state): State<Arc<AppState>>) -> impl IntoResponse {
info!(message = "got get messages request!");

let q = sqlx::query!("select * from guestbook")
Expand Down
6 changes: 3 additions & 3 deletions src/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

pub mod metrics;

use axum::{extract::Extension, http::StatusCode, middleware, routing, Router, Server};
use axum::{http::StatusCode, middleware, routing, Router, Server};
use std::net::SocketAddr;
use tower_http::trace::{DefaultMakeSpan, TraceLayer};
use tracing::{error, Level};
Expand All @@ -35,15 +35,15 @@ use tracing::{error, Level};
pub async fn serve<S>(
http_address: SocketAddr,
metrics_address: Option<SocketAddr>,
router: Router,
router: Router<S>,
state: S,
) where
S: Send + Sync + Clone + 'static,
{
// create primary application router and server
// applying handler state if we have it, and default metrics/tracing middleware
let r = router
.layer(Extension(state))
.with_state(state)
.route_layer(middleware::from_fn(metrics::middleware)) // only record matched routes
.layer(
TraceLayer::new_for_http().make_span_with(
Expand Down
Loading