Skip to content

Commit

Permalink
feat: Add an axum/with-state example using updated generic AxumService (
Browse files Browse the repository at this point in the history
#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
morlinbrot and oddgrd committed Jun 5, 2023
1 parent 2474a4e commit 607ee5b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
10 changes: 10 additions & 0 deletions axum/with-state/Cargo.toml
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" }
23 changes: 23 additions & 0 deletions axum/with-state/src/main.rs
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())
}

0 comments on commit 607ee5b

Please sign in to comment.