-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ca12a9e
commit 37651d7
Showing
7 changed files
with
79 additions
and
3 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
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,75 @@ | ||
# Exploring Shuttle | ||
|
||
Open the `api/shuttle` folder and look for the `src/main.rs` file. This is the entry point of our application. | ||
|
||
You'll see something like this: | ||
|
||
```rust | ||
use actix_web::{get, web::ServiceConfig}; | ||
use shuttle_actix_web::ShuttleActixWeb; | ||
|
||
#[get("/")] | ||
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()) | ||
} | ||
``` | ||
|
||
Shuttle has generated a simple `hello-world` [Actix-web](https://actix.rs) application for us. | ||
|
||
As you can see, it's pretty straight-forward. | ||
|
||
The `actix_web` function is the entry point of our application. It returns a `ShuttleActixWeb` instance that will be used by Shuttle to run our application. | ||
|
||
In this function, we're going to configure our different routes. In this case, we only have one route: `/`, which is mapped to the `hello_world` function. | ||
|
||
## Let's run it! | ||
|
||
In the **root of the project**, run the following command: | ||
|
||
```bash | ||
cargo shuttle run | ||
``` | ||
|
||
You should see something like this: | ||
|
||
![shuttle_run](./assets/22/cargo_shuttle_run.png) | ||
|
||
Now *curl* the `/` route: | ||
|
||
```bash | ||
curl localhost:8000 | ||
``` | ||
|
||
Or *open* it in your browser. | ||
|
||
Hopefully, **you should see a greeting** in your screen! | ||
|
||
And that's how easy it is to create a simple API with [Shuttle](https://www.shuttle.rs)! | ||
|
||
```admonish | ||
We're using [Actix-web](https://actix.rs) as our web framework, but you can any other framework supported by Shuttle. | ||
Check out the [Shuttle documentation](https://docs.shuttle.rs/introduction/welcome) to learn more. Browse through the `Examples` section to see how to use Shuttle with other frameworks. | ||
[Shuttle](https://www.shuttle.rs/) supports the following frameworks: | ||
- [Actix-web](https://actix.rs) | ||
- [Axum](https://github.com/tokio-rs/axum) | ||
- [Salvo](https://next.salvo.rs/) | ||
- [Poem](https://github.com/poem-web/poem) | ||
- [Thruster](https://github.com/thruster-rs/Thruster) | ||
- [Tower](https://github.com/tower-rs/tower) | ||
- [Warp](https://github.com/seanmonstar/warp) | ||
- [Rocket](https://rocket.rs) | ||
- [Tide](https://github.com/http-rs/tide) | ||
``` |
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
File renamed without changes
File renamed without changes
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.