Skip to content
Closed
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
43 changes: 42 additions & 1 deletion examples/other.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: "Other Examples"
description: "This section contains examples for the following frameworks: Tower, Warp, Salvo, Poem, Thruster, and Tide."
description: "This section contains examples for the following frameworks: Poem, Rama, Salvo, Thruster, Tide, Tower, and Warp."
---

### Hello World
Expand All @@ -12,6 +12,47 @@ In order to get started, initialize your project with `shuttle init` and pick th
Once you are done, your project should be setup with all the required dependencies so go ahead and copy/paste the relevant code snippet from below into your `main.rs` file.

<CodeGroup>
```rust Rama
use rama::{
Context, Layer,
error::ErrorContext,
http::{
StatusCode,
layer::forwarded::GetForwardedHeaderLayer,
service::web::{Router, response::Result},
},
net::forwarded::Forwarded,
};

async fn hello_world(ctx: Context<()>) -> Result<String> {
Ok(match ctx.get::<Forwarded>() {
Some(forwarded) => format!(
"Hello cloud user @ {}!",
forwarded
.client_ip()
.context("missing IP information from user")
.map_err(|err| (StatusCode::INTERNAL_SERVER_ERROR, err.to_string()))?
),
None => "Hello local user! Are you developing?".to_owned(),
})
}

#[shuttle_runtime::main]
async fn main() -> Result<impl shuttle_rama::ShuttleService, shuttle_rama::ShuttleError> {
let router = Router::new().get("/", hello_world);

let app =
// Shuttle sits behind a load-balancer,
// so in case you want the real IP of the user,
// you need to ensure this headers is handled.
//
// Learn more at <https://docs.shuttle.dev/docs/deployment-environment#https-traffic>
GetForwardedHeaderLayer::x_forwarded_for().into_layer(router);

Ok(shuttle_rama::RamaService::application(app))
}
```

```rust Tower
use std::convert::Infallible;
use std::future::Future;
Expand Down
11 changes: 6 additions & 5 deletions welcome/introduction.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,16 @@ Any app that can bind to a socket and accept incoming HTTP traffic can run on Sh

To make life easier we have implemented all the boilerplate required for these Rust web frameworks. Get started with just a few lines of code.

- [Axum](/examples/axum)
- [Actix Web](/examples/actix)
- [Axum](/examples/axum)
- [Poem](/examples/other)
- [Rama](/examples/other)
- [Rocket](/examples/rocket)
- [Warp](/examples/other)
- [Tower](/examples/other)
- [Salvo](/examples/other)
- [Poem](/examples/other)
- [Tide](/examples/other)
- [Thruster](/examples/other)
- [Tide](/examples/other)
- [Tower](/examples/other)
- [Warp](/examples/other)

The Discord Bot building frameworks [Serenity](/examples/serenity) and [Poise](/examples/poise) are also officially supported.

Expand Down