
The videos goes over the agenda and discusses why you may want to consider learning and using rust
Build a full stack app with a Yew frontend and an Axum backend, connected to Postgres, exposing a products API to add, list, and delete products.
Learn how to install Rust from rust-lang.org, choose your system (Windows, Mac, or WSL), verify the installation with rustc --version, and update with rustup update.
Set up VS Code for Rust development by installing Crates extension, Rust Analyzer, and Tonda client extensions, then enable automatic builds with cargo watch and run on change.
Declare variables and functions in Rust within the main function, and print values using the println! macro; understand immutable versus mutable bindings, and observe i32 and f64 types during updates.
Explore writing and using functions in Rust, including fn syntax, parameter types (i32), return values, and printing results, while contrasting mutable and immutable variables and previewing ownership concepts.
Learn how to refactor a rust project using modules, splitting code into variables and functions, making the run method public, and wiring modules in main to compile and run.
Explore Rust data types, including scalar types like integers, floats, booleans, and characters, with size variations and signed or unsigned representations, and note how type choices affect performance and memory.
Explore Rust compound data types by comparing tuples and arrays, learning fixed-length storage, type constraints, and element access to understand how to combine data.
Create and manipulate vectors by making them mutable, pushing values, and printing results. Learn how vectors enforce homogeneous types, how to get length, and how to pop items.
Learn to use Rust hash maps to store key value pairs, import std hash map, insert California and Florida, convert with to_string, then print with the print line macro.
Continue exploring hash maps by adding Georgia and other states, removing Florida, and printing results, then practice for loops and iterating over hash maps to reinforce Rust hash map concepts.
Explore Rust control flow with if else and match, printing age-based outcomes such as 'you can drink' or 'you are too young', and save reusable hash maps for later refactoring.
Learn how to use for loops, ranges, and while loops in Rust to iterate over scores, print results, and count down from ten, reinforcing core control flow concepts.
Explore Rust structs and tuple-like forms, define a car with make, model, and year, and a location with latitude and longitude, then print fields using println! and dot notation.
Learn how to implement methods on a Rust struct using impl, including a new constructor and a describe method that returns a formatted car description.
Explore working with json in Rust using serde_json to parse api data, create and access nested structures like address and languages and country, and print specific fields.
Master Rust ownership and borrowing in full stack development with axum, yew, and sqlx, recognizing that values have a single owner, drop at scope, and can be borrowed via references.
Set up the Axiom web api backend, configure the web server, add tracing, and implement create, read, update, and delete functions for a front-end friendly api.
use axum::{
routing::{get},Router,
};
use tower_http::cors::{Any, CorsLayer};
#[tokio::main]
async fn main() {
//tracing
tracing_subscriber::fmt::init();
// add cors
let cors = CorsLayer::new()
.allow_origin(Any);
let app = Router::new()
.route("/", get(root))
.layer(cors);
tracing::debug!("listening on {}", "0.0.0.0:3000");
println!(" Listening on port {}" , "0.0.0.0:3000" );
axum::Server::bind(&"0.0.0.0:3000".parse().unwrap())
.serve(app.into_make_service())
.await
.unwrap();
}
// basic handler that responds with a static string
async fn root() -> &'static str {
"Hello, REST AXUM API"
}
Learn how to automate Rust server restarts with cargo watch, enabling auto-recompile and running via cargo run with a live server on port 3000.
Add cors as a layer to your AXUM routes using tower http so the api can be requested from any user interface or any browser.
learn how to connect a Rust web app to a database using sqlx, configure dependencies and an env file, and establish a pool connection for Postgres, MySQL, and SQLite.
Add a Postgres table to the database if it does not exist, using a Rust string literal for the SQL query, executing it with execute, and verifying compilation.
Build an Axum api to create a product by posting json to a handler, inserting name and price into the products table with sqlx.
Develop an Axum get all products api with a database pool and SQLx that fetches all products via select, returning a json vector of Product with an id field.
Implement an Axum get route to fetch product by id using a path extractor and database pool, with select id, name, price from products where id = ?.
Create a delete product API in axum using a write query to remove a product by id and return json 'product deleted successfully'; wire the handler in main.rs.
Update a product in the axum api by reusing the delete product pattern, binding the product name and price, and returning a json response that signals the update is successful.
Learn to build a full stack Rust app with Yew frontend and Axum API, covering components, styling, form handling, and data flow using use data and use effect.
Cargo.toml
[package]
name = "frontend"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
yew = { version = "0.20.0", features = ["csr"] }
yew-router = "0.17"
serde = "1.0.152"
serde_json = "1.0.91"
wasm-bindgen-futures = "0.4.33"
reqwest = { version = "0.11.13", features = ["json"] }
web-sys = {version = "0.3.60", features = ["HtmlInputElement"] }
gloo-console = "0.2.3"
Learn to style a Yew app by adding a stylesheet, defining color variables, and applying container and typography rules, then preview the design in the browser.
Learn to build two Yew components—a form and a products list—and wire them into the main file using mod imports to render a publicly exposed list of products.
below is the final products.rs file
use serde::{Deserialize, Serialize};
use yew::prelude::*;
use yew_router::prelude::*;
use crate::router::Route;
#[derive(Serialize, Deserialize, Debug)]
pub struct Product {
id: i32,
name: String,
price: i32
}
#[function_component]
pub fn Products() -> Html {
let data: UseStateHandle<Vec<Product>> = use_state(|| vec![]);
{
let data_clone = data.clone();
use_effect(move ||{
wasm_bindgen_futures::spawn_local( async move {
let fetched_data = reqwest::get("http://localhost:3000/api/products")
.await
.expect("cannot get data from url")
.json::<Vec<Product>>()
.await
.expect("cannot convert to json");
data_clone.set(fetched_data);
});
|| ()
});
}
let products = data.iter().map(|product| html! {
<ul>
<li key={product.id}>{format!("Name: {}, Price: {}", product.name, product.price)}</li>
</ul>
}).collect::<Html>();
html! {
<div class="container">
<button class="btn-primary">
<Link<Route> to={Route::AddProduct}>{ "Add new Product" }</Link<Route>>
</button>
<h2>{"List of Products: "} {data.len()} </h2>
<p>{products}</p>
</div>
}
}
let products = data.iter().map(|product| html! {
<ul>
<li key={product.id}>{format!("Name: {}, Price: {}", product.name, product.price)}</li>
</ul>
}).collect::<Html>();
Learn how to implement the use_effect hook in Yew to fetch data on page load, move data-fetching into an effect, and manage state for a responsive Rust web app.
Install and configure dependencies to build a web form in a Rust project, then implement an HTML input element and form wiring in main, with Glow output and Cargo.toml features.
Create a dynamic form with name and price fields, wire inputs to node refs, clone refs for reuse, and implement a click handler to submit data and log the action.
===================================
#### Connecting frontend and server ####
create and add to Cargo.toml
[workspace]
members = [
"server", "frontend"
]
#create and add to .gitignore
target/
dist/
.env
create frontend/Trunk.toml and add contents
[build]
target = "index.html"
dist = "../dist"
now you can run: trunk serve
# now go to server/main.rs
axum::response::IntoResponse
axum::http::StatusCode,
use std::io;
//serving frontend static files
let serve_dir = ServeDir::new("../frontend/dist").not_found_service(ServeFile::new("../dist/frontend/index.html"));
let serve_dir = get_service(serve_dir).handle_error(handle_error);
# add to router
.nest_service("/", serve_dir.clone())
.fallback_service(serve_dir.clone());
# add handle error fn
async fn handle_error(_err: io::Error) -> impl IntoResponse {
(StatusCode::INTERNAL_SERVER_ERROR, "Something went wrong...")
}
# change current / to /home
cd into backend: cargo watch -x run
=========================================
Post form data to the back-end API by building a JSON payload with name and price (as i32) using request create, sending to /api/products, and successfully adding the product.
Learn how to style the form and inputs, including the name and price fields, apply classes like form input and btn primary, and verify the appearance in the browser.
final router.rs
use yew_router::prelude::*;
use yew::prelude::*;
use crate::products::Products;
use crate::form::Form;
#[derive(Clone, Routable, PartialEq)]
pub enum Route {
#[at("/")]
Home,
#[at("/addproduct")]
AddProduct,
#[at("/about")]
About,
#[not_found]
#[at("/404")]
NotFound,
}
pub fn switch(routes: Route) -> Html {
match routes {
Route::Home => html! { <Products /> },
Route::AddProduct => html! { <Form />},
Route::About => html! { <h1>{ "About us " }</h1>},
Route::NotFound => html! { <h1>{ "404" }</h1> },
}
}
Master Yew routing by adding components and navigation in a full stack Rust app. Wire the router, register components, and navigate from add product to home page.
You will build a full-stack web app using the rust programming language. We will be building a fully functional CRUD Server API using AXUM, SQLx, and Postgres. Then we will build a fully functional frontend in rust using the Yew framework (Yew looks like ReactJS but in Rust). We will then connect the front end and the back end to run from the same port/URL. You will learn how to create Yew components, routing, create forms and handle GET and POST requests using the rust reqwest crate in the front end. This course is good for developers who already know at least one programming language and have some web development experience. It is not a course for folks who are completely new to programming.
Rust is the most loved programming language for the past several years according to StackOverflow. All the big tech companies are now using rust and a lot of startups are using rust. More so, a lot of the newer blockchain projects are building with rust. The rust programming language is growing very rapidly.
This course will help you start developing in rust very fast, as you will build a real full-stack app. You can use the concepts to expand your rust dev options.
The course is divided into 3 main sections. Section 1 is an intro to rust. You can skip this section if you are already familiar with the material. Section 2 will cover the Server API dev using AXUM and section 3 covers developing frontend apps using the popular Yew framework.
Full source code provided at the end of the course.