-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add an axum/with-state example using updated generic AxumService (
#52) * feat: Add an axum/with-state example using updated generic AxumService * chore: Remove local dependencies * chore: bump to v0.18 --------- Co-authored-by: Oddbjørn Grødem <29732646+oddgrd@users.noreply.github.com>
- Loading branch information
1 parent
2474a4e
commit 607ee5b
Showing
2 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[package] | ||
name = "with-state" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
axum = "0.6.10" | ||
shuttle-axum = { version = "0.18.0" } | ||
shuttle-runtime = { version = "0.18.0" } | ||
tokio = { version = "1.26.0" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use std::sync::Arc; | ||
|
||
use axum::{extract::State, response::IntoResponse, routing::get, Router}; | ||
|
||
async fn hello_world(State(state): State<Arc<AppState>>) -> impl IntoResponse { | ||
state.msg | ||
} | ||
|
||
#[derive(Clone)] | ||
struct AppState { | ||
msg: &'static str, | ||
} | ||
|
||
#[shuttle_runtime::main] | ||
async fn axum() -> shuttle_axum::ShuttleAxum { | ||
let state = Arc::new(AppState { | ||
msg: "Hello, world!", | ||
}); | ||
|
||
let router = Router::new().route("/", get(hello_world)).with_state(state); | ||
|
||
Ok(router.into()) | ||
} |