Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: move from tuono_lib to tuono #441

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
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
Prev Previous commit
change docs from tuono_lib to tuono
  • Loading branch information
jacobhq committed Jan 27, 2025
commit 58aaffe542e0c0add6d30cbbca130893e9d363f4
2 changes: 1 addition & 1 deletion apps/documentation/Cargo.toml
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ name = "tuono"
path = ".tuono/main.rs"

[dependencies]
tuono_lib = "0.17.5"
tuono = { package = "tuono_lib", version = "0.17.5" }
glob = "0.3.1"
time = { version = "0.3", features = ["macros"] }
serde = { version = "1.0.202", features = ["derive"] }
Original file line number Diff line number Diff line change
@@ -45,7 +45,7 @@ Now the `ApplicationState` is available on all the handlers as following:
```rs
// src/routes/index.rs

#[tuono_lib::handler]
#[tuono::handler]
// The first argument always is the Request
// The ApplicationState arguments are optional. You can use just the ones you need
// to use in the handler (with no specific order).
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ Clear the `index.rs` file and paste:
// src/routes/index.rs
use serde::{Deserialize, Serialize};
use reqwest::Client;
use tuono_lib::{Props, Request, Response};
use tuono::{Props, Request, Response};

const ALL_POKEMON: &str = "https://pokeapi.co/api/v2/pokemon?limit=151";

@@ -44,7 +44,7 @@ struct Pokemon {
url: String,
}

#[tuono_lib::handler]
#[tuono::handler]
async fn get_all_pokemons(_req: Request, fetch: Client) -> Response {
return match fetch.get(ALL_POKEMON).send().await {
Ok(res) => {
@@ -93,7 +93,7 @@ name = "tuono"
path = ".tuono/main.rs"

[dependencies]
tuono_lib = "0.14.0" # the version might be different
tuono = { package = "tuono_lib", version = "0.17.5" } # the version might be different
serde = { version = "1.0.202", features = ["derive"] }
++ reqwest = "0.12.9" # the version might be different
```
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ Let’s first work on the server side file. Paste into the new `[pokemon].rs` fi
// src/routes/pokemons/[pokemon].rs
use serde::{Deserialize, Serialize};
use reqwest::Client;
use tuono_lib::{Props, Request, Response};
use tuono::{Props, Request, Response};

const POKEMON_API: &str = "https://pokeapi.co/api/v2/pokemon";

@@ -45,7 +45,7 @@ struct Pokemon {
height: u16,
}

#[tuono_lib::handler]
#[tuono::handler]
async fn get_pokemon(req: Request, fetch: Client) -> Response {
// The param `pokemon` is defined in the route filename [pokemon].rs
let pokemon = req.params.get("pokemon").unwrap();
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ Let's see how it works!
use serde::{Deserialize, Serialize};
-- use reqwest::Client;
++ use reqwest::{Client, StatusCode};
use tuono_lib::{Props, Request, Response};
use tuono::{Props, Request, Response};

const POKEMON_API: &str = "https://pokeapi.co/api/v2/pokemon";

@@ -41,7 +41,7 @@ struct Pokemon {
height: u16,
}

#[tuono_lib::handler]
#[tuono::handler]
async fn get_pokemon(req: Request, fetch: Client) -> Response {
// The param `pokemon` is defined in the route filename [pokemon].rs
let pokemon = req.params.get("pokemon").unwrap();
@@ -71,7 +71,7 @@ async fn get_pokemon(req: Request, fetch: Client) -> Response {
use serde::{Deserialize, Serialize};
-- use reqwest::Client;
++ use reqwest::{Client, StatusCode};
use tuono_lib::{Props, Request, Response};
use tuono::{Props, Request, Response};

const ALL_POKEMON: &str = "https://pokeapi.co/api/v2/pokemon?limit=151";

@@ -86,7 +86,7 @@ struct Pokemon {
url: String,
}

#[tuono_lib::handler]
#[tuono::handler]
async fn get_all_pokemons(_req: Request, fetch: Client) -> Response {
return match fetch.get(ALL_POKEMON).send().await {
Ok(res) => {
Original file line number Diff line number Diff line change
@@ -25,9 +25,9 @@ First, let's create a new route by just creating a new file `/pokemons/GOAT.rs`

```rs
// src/routes/pokemons/GOAT.rs
use tuono_lib::{Request, Response};
use tuono::{Request, Response};

#[tuono_lib::handler]
#[tuono::handler]
async fn redirect_to_goat(_req: Request) -> Response {
// Of course the GOAT is mewtwo - feel free to select your favourite 😉
Response::Redirect("/pokemons/mewtwo".to_string())