Getting Started

Tidos is a SSR component framework. It lets you write HTML components directly in Rust. Tidos works with your favourite frameworks.

1. Add to Cargo.toml

1[dependencies]
2tidos = { version = "0.8.0-rc.1", features = ["rocket"] }
3rocket = "0.5"
1[dependencies]
2tidos = { version = "0.8.0-rc.1", features = ["actix-web"] }
3actix-web = "4"
1[dependencies]
2tidos = { version = "0.8.0-rc.1", features = ["axum"] }
3axum = "0.8"
4tokio = { version = "1", features = ["full"] }
1[dependencies]
2tidos = { version = "0.8.0-rc.1", features = ["warp"] }
3warp = "0.4"
4tokio = { version = "1", features = ["full"] }
1[dependencies]
2tidos = "0.8.0-rc.1"

2. Create your first route

Use the page! macro inside a route handler to return a rendered HTML page:

1use tidos::{page, Page};
2use rocket::{get, routes};
3
4#[get("/")]
5pub fn index() -> Page {
6 page! {
7 <main>
8 <h1>{"Hello from Tidos!"}</h1>
9 </main>
10 }
11}
12
13#[rocket::main]
14async fn main() {
15 rocket::build()
16 .mount("/", routes![index])
17 .launch()
18 .await
19 .unwrap();
20}
1use actix_web::{get, App, HttpServer, HttpResponse};
2use tidos::{page, Page};
3
4#[get("/")]
5async fn index() -> HttpResponse {
6 let page: Page = page! {
7 <main>
8 <h1>{"Hello from Tidos!"}</h1>
9 </main>
10 };
11 HttpResponse::Ok()
12 .content_type("text/html; charset=utf-8")
13 .body(page.to_string())
14}
15
16#[actix_web::main]
17async fn main() -> std::io::Result<()> {
18 HttpServer::new(|| App::new().service(index))
19 .bind("127.0.0.1:8080")?
20 .run()
21 .await
22}
1use axum::{response::IntoResponse, routing::get, Router};
2use tidos::{page, Page};
3
4async fn index() -> impl IntoResponse {
5 page! {
6 <main>
7 <h1>{"Hello from Tidos!"}</h1>
8 </main>
9 }
10}
11
12#[tokio::main]
13async fn main() {
14 let app = Router::new().route("/", get(index));
15 let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
16 axum::serve(listener, app).await.unwrap();
17}
1use warp::Filter;
2use tidos::{page, Page};
3
4#[tokio::main]
5async fn main() {
6 let route = warp::get()
7 .and(warp::path::end())
8 .map(|| {
9 warp::reply::html(page! {
10 <main>
11 <h1>{"Hello from Tidos!"}</h1>
12 </main>
13 }.to_string())
14 });
15 warp::serve(route).run(([127, 0, 0, 1], 3030)).await;
16}
1use tidos::{page, Page};
2
3fn main() {
4 let html: Page = page! {
5 <main>
6 <h1>{"Hello from Tidos!"}</h1>
7 </main>
8 };
9 println!("{}", html);
10}

Live reloading during development

Rust has no native hot module reloading, so retyping cargo run after every change gets tedious. We recommend using Watchexec as it rebuilds and restarts your server automatically whenever you save a file. We use it for the Tidos documentation website itself.

1# install once
2cargo install watchexec-cli
3
4# rebuild & restart on every save
5watchexec -r -e rs -- cargo run
6
7# with multiple binaries, name the one to run
8watchexec -r -e rs -- cargo run --bin my_app

Next steps

You now have a page rendering. Next, learn how to build reusable Components with the view! macro, control flow, slots, and scoped CSS.