Skip to content
Merged
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
2 changes: 1 addition & 1 deletion docs/src/backend/00_backend.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ The goal of this part of the workshop is to create a simple API that will be use

## Tools and Frameworks

- [Actix-web](https://actix.rs/)
- [Actix Web](https://actix.rs/)
- [SQLx](https://github.com/launchbadge/sqlx)
- [Shuttle](https://www.shuttle.rs/)

Expand Down
4 changes: 2 additions & 2 deletions docs/src/backend/01_workspace_setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ For the `API`, we will create **two crates**:
Having two different crates is totally optional, but it will allow us to have a cleaner project structure and will make it easy to reuse the `API` library code if we decide to not use [Shuttle](https://www.shuttle.rs/) in the future.

``` admonish tip title="Shuttle"
Shuttle will allow us to run our API locally and deploy it to the cloud with minial effort but it is not required to build the API.
Shuttle will allow us to run our API locally and deploy it to the cloud with minimal effort but it is not required to build the API.

We could decide to use a different executable to run our API that would use the `lib` crate as a dependency. For instance, we could use `Actix-web` directly to create such a binary and release it as a Docker image.
We could decide to use a different executable to run our API that would use the `lib` crate as a dependency. For instance, we could use Actix Web directly to create such a binary and release it as a Docker image.
```

### Creating the `lib` crate
Expand Down
6 changes: 3 additions & 3 deletions docs/src/backend/02_shuttle.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ async fn actix_web(
}
```

[Shuttle](https://www.shuttle.rs) has generated a simple `hello-world` [Actix-web](https://actix.rs) application for us.
[Shuttle](https://www.shuttle.rs) has generated a simple `hello-world` [Actix Web](https://actix.rs) application for us.

As you can see, it's pretty straight-forward.

Expand Down Expand Up @@ -59,12 +59,12 @@ And that's how easy it is to create a simple API with [Shuttle](https://www.shut
> Try to add more routes and see what happens!

```admonish
We're using [Actix-web](https://actix.rs) as our web framework, but **you can use any other framework** supported by [Shuttle](https://www.shuttle.rs).
We're using [Actix Web](https://actix.rs) as our web framework, but **you can use any other framework** supported by [Shuttle](https://www.shuttle.rs).

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](https://www.shuttle.rs) with other frameworks.

At the moment of writing this, [Shuttle](https://www.shuttle.rs/) supports:
- [Actix-web](https://actix.rs)
- [Actix Web](https://actix.rs)
- [Axum](https://github.com/tokio-rs/axum)
- [Salvo](https://next.salvo.rs/)
- [Poem](https://github.com/poem-web/poem)
Expand Down
2 changes: 1 addition & 1 deletion docs/src/backend/03_deploying_with_shuttle.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ The problem is that we haven't created the project environment yet. Let's do tha
cargo shuttle project start
```

If everthing went well, you should see something like this:
If everything went well, you should see something like this:

![project started](../assets/backend/03/project_started.png)

Expand Down
8 changes: 3 additions & 5 deletions docs/src/backend/07_connecting_the_database.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This will help us to get acquainted with [SQLx](https://github.com/launchbadge/s

Don't worry about how to retrieve the information from the database, we will do that in a moment. Just focus on creating and endpoint that will return a string. The string can be anything you want and the route should be `/version`.

If you're not sure about how to do it, uncollapse the section below to see the solution.
If you're not sure about how to do it, expand the section below to see the solution.

~~~admonish tip title="Solution" collapsible=true
Open the `main.rs` file in the `api > shuttle > src` folder and add the following code:
Expand Down Expand Up @@ -124,7 +124,7 @@ async fn version(db: actix_web::web::Data<sqlx::PgPool>) -> String {

There are a couple of things going on here, so let's break it down.

First of all, it's worth noticing that **we changed the return type** of the function to `String`. This obbeys to two different reasons:
First of all, it's worth noticing that **we changed the return type** of the function to `String`. This is for two different reasons:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the only change I couldn't quite figure out what "obbeys" was trying to say, hope the semantics make sense.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, totally makes sense, Thank you for the fix @robjtede ❤️


1. We don't want our endpoint to fail. If the query fails, we will have to return an error message as a `String`.
1. We need that return to be a `String` because the version of the database will come to us as a `String`.
Expand All @@ -133,7 +133,7 @@ On the other hand, we have the [sqlx::query_scalar](https://docs.rs/sqlx/latest/

As you can see, the **query is pretty simple**. We're just selecting the version of the database. The most interesting part in there is that we need to use the `.get_ref()` method to get a **reference** to the inner `sqlx::PgPool` from the `actix_web::web::Data<sqlx::PgPool>`.

Finally, we have the [match expression](https://doc.rust-lang.org/reference/expressions/match-expr.html). The [sqlx::query_scalar](https://docs.rs/sqlx/latest/sqlx/query/struct.QueryScalar.html) function will return a [Result](https://doc.rust-lang.org/std/result/enum.Result.html) with either the version of the database or an error. With the [match expression](https://doc.rust-lang.org/reference/expressions/match-expr.html) we're coverging both cases and we will make sure that we will always return a `String`.
Finally, we have the [match expression](https://doc.rust-lang.org/reference/expressions/match-expr.html). The [sqlx::query_scalar](https://docs.rs/sqlx/latest/sqlx/query/struct.QueryScalar.html) function will return a [Result](https://doc.rust-lang.org/std/result/enum.Result.html) with either the version of the database or an error. With the [match expression](https://doc.rust-lang.org/reference/expressions/match-expr.html) we're covering both cases and we will make sure that we will always return a `String`.

```admonish tip
Note that most of the time we don't need the return keyword in Rust. The last expression in a function will be the return value.
Expand All @@ -153,5 +153,3 @@ For now, let's commit our changes:
git add .
git commit -m "add version endpoint"
```


2 changes: 1 addition & 1 deletion docs/src/backend/12_library.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

The idea behind this section is to **move our endpoints** to a library so that we can **reuse** them in case we want to provide a different binary that doesn't rely on [Shuttle](https://shuttle.rs).

Imagine, for example, that you want to deploy your API to your cloud of choice. Most probably you'll want to use a container to do so. In that case, having our endpoints in a library will allow us to create a binary that works purely on [Actix-web](https://actix.rs).
Imagine, for example, that you want to deploy your API to your cloud of choice. Most probably you'll want to use a container to do so. In that case, having our endpoints in a library will allow us to create a binary that works purely on [Actix Web](https://actix.rs).

## Adding a local dependency

Expand Down
2 changes: 1 addition & 1 deletion docs/src/backend/13_health_check.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async fn health() -> HttpResponse {

- Configure the services in your shuttle crate. Remove the previous services and add the new one.

Your `api > shuttle> src > main.rs` file should look like this:
Your `api > shuttle > src > main.rs` file should look like this:

```rust
use actix_web::web::ServiceConfig;
Expand Down
3 changes: 1 addition & 2 deletions docs/src/backend/22_implementing_endpoints.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Indeed, we **shouldn't care about the implementation details** of the `FilmRepos
So, it seems clear that we need to get access to the `FilmRepository` instance in our handlers. But how can we do that?

```admonish tip
Refresh your memory by reading about how to handle State in Actix-web in the [official documentation](https://actix.rs/docs/application/#state).
Refresh your memory by reading about how to handle State in Actix Web in the [official documentation](https://actix.rs/docs/application/#state).
```

As you can see, it should be pretty straightforward isn't it? But, wait a minute. We have a problem here.
Expand Down Expand Up @@ -152,4 +152,3 @@ Commit your changes:
git add .
git commit -m "implement film endpoints"
```

4 changes: 2 additions & 2 deletions docs/src/frontend/03_06_building.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ Inside our workspace **root** we some handy `cargo-make` tasks for the frontend
makers front-build
```

This will build our frontend for production and place the output in the `shuttle/static` directory. Now we can serve our frontend with the backend. Letś deploy it with Shuttle and see our results.
This will build our frontend for production and place the output in the `shuttle/static` directory. Now we can serve our frontend with the backend. Let's deploy it with Shuttle and see our results.

```bash
cargo shuttle deploy
```
```
2 changes: 1 addition & 1 deletion docs/src/frontend/03_frontend.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Frontend

In this guide, we'll be using [Dioxus](https://dioxuslabs.com/) as the frontend for our project. Dioxus is a portable, performant, and ergonomic framework for building cross-platform user interfaces in Rust. Heavily inspired by React, Dioxus allows you to build apps for the Web, Desktop, Mobile, and more. Its core implementation can run anywhere with no platform-dependent linking, which means it's not intrinsically linked to WebSys like many other Rust frontend toolkits. However, it's important to note that Dioxus hasn't reached a stable release yet, so some APIs, particularly for Desktop, may still be inestable.
In this guide, we'll be using [Dioxus](https://dioxuslabs.com/) as the frontend for our project. Dioxus is a portable, performant, and ergonomic framework for building cross-platform user interfaces in Rust. Heavily inspired by React, Dioxus allows you to build apps for the Web, Desktop, Mobile, and more. Its core implementation can run anywhere with no platform-dependent linking, which means it's not intrinsically linked to WebSys like many other Rust frontend toolkits. However, it's important to note that Dioxus hasn't reached a stable release yet, so some APIs, particularly for Desktop, may still be unstable.

As for styling our app, we'll be using [Tailwind CSS](https://tailwindcss.com/). Tailwind is a highly customizable, low-level CSS framework that gives you all of the building blocks you need to build bespoke designs without any annoying opinionated styles you have to fight to override. You can set it up in your project, build something with it in an online playground, and even learn more about it directly from the team on their channel. Tailwind also offers a set of beautiful UI components crafted by its creators to help you speed up your development process​.

Expand Down