forked from shuttle-hq/shuttle-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: initial commit of shuttle-next example * feat: add post endpoint * feat: convert all examples to bins * feat: remove syncwrapper * feat: refactor axum hello-world * feat: from impl for AxumService * feat: update all axum examples * feat: update actix examples (postgres not working) * feat: update poem examples * feat: update poise example * feat: update rocket examples * feat: update serenity and salvo * feat: update thruster examples * feat: update the tower and warp examples * feat: update tide examples * misc: bump versions (shuttle-hq#28) * misc: v0.12.0-rc1 (shuttle-hq#29) * refactor: update next example (shuttle-hq#30) * chore: v0.12.0 (shuttle-hq#32) --------- Co-authored-by: oddgrd <[email protected]>
- Loading branch information
Showing
58 changed files
with
292 additions
and
241 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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
target/ | ||
Cargo.lock | ||
.cargo |
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
This file was deleted.
Oops, something went wrong.
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,17 @@ | ||
use actix_web::{get, web::ServiceConfig}; | ||
use shuttle_actix_web::ShuttleActixWeb; | ||
|
||
#[get("/hello")] | ||
async fn hello_world() -> &'static str { | ||
"Hello World!" | ||
} | ||
|
||
#[shuttle_runtime::main] | ||
async fn actix_web( | ||
) -> ShuttleActixWeb<impl FnOnce(&mut ServiceConfig) + Send + Clone + 'static> { | ||
let config = move |cfg: &mut ServiceConfig| { | ||
cfg.service(hello_world); | ||
}; | ||
|
||
Ok(config.into()) | ||
} |
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
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
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
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
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
This file was deleted.
Oops, something went wrong.
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,12 @@ | ||
use axum::{routing::get, Router}; | ||
|
||
async fn hello_world() -> &'static str { | ||
"Hello, world!" | ||
} | ||
|
||
#[shuttle_runtime::main] | ||
async fn axum() -> shuttle_axum::ShuttleAxum { | ||
let router = Router::new().route("/hello", get(hello_world)); | ||
|
||
Ok(router.into()) | ||
} |
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
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
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
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
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
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
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,13 @@ | ||
[package] | ||
name = "hello-world" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[lib] | ||
crate-type = [ "cdylib" ] | ||
|
||
[dependencies] | ||
# TODO: bump to 0.9 before merge | ||
shuttle-next = "0.12.0" | ||
tracing = "0.1.37" | ||
futures = "0.3.25" |
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,33 @@ | ||
shuttle_next::app! { | ||
use futures::TryStreamExt; | ||
use tracing::debug; | ||
use shuttle_next::body::StreamBody; | ||
use shuttle_next::extract::BodyStream; | ||
use shuttle_next::response::{Response, IntoResponse}; | ||
|
||
#[shuttle_next::endpoint(method = get, route = "/hello")] | ||
async fn hello() -> &'static str { | ||
"Hello, World!" | ||
} | ||
|
||
// We can also use tracing/log macros directly: | ||
#[shuttle_next::endpoint(method = get, route = "/goodbye")] | ||
async fn goodbye() -> &'static str { | ||
debug!("goodbye endpoint called"); | ||
"Goodbye, World!" | ||
} | ||
|
||
// We can also extract the http body in our handlers. | ||
// The endpoint below takes the body from the request using the axum `BodyStream` | ||
// extractor, lazily maps its bytes to uppercase and streams it back in our response: | ||
#[shuttle_next::endpoint(method = post, route = "/uppercase")] | ||
async fn uppercase(body: BodyStream) -> impl IntoResponse { | ||
let chunk_stream = body.map_ok(|chunk| { | ||
chunk | ||
.iter() | ||
.map(|byte| byte.to_ascii_uppercase()) | ||
.collect::<Vec<u8>>() | ||
}); | ||
Response::new(StreamBody::new(chunk_stream)) | ||
} | ||
} |
Oops, something went wrong.