### Activate Environment and Install Dependencies Source: https://github.com/levkk/rwf/blob/main/examples/django/README.md Activates the previously created virtual environment and installs all necessary Python packages listed in the 'requirements.txt' file. This step ensures all project dependencies are met. ```bash source venv/bin/activate pip install -r requirements.txt ``` -------------------------------- ### Install Rwf CLI Source: https://github.com/levkk/rwf/blob/main/docs/docs/user-guides/build-your-app/index.md Installs the Rwf Command Line Interface using Cargo, the Rust package manager. This command is the first step required to start building applications with Rwf. ```shell cargo install rwf-cli ``` -------------------------------- ### Launch Rwf Web Server Source: https://github.com/levkk/rwf/blob/main/docs/docs/index.md Shows how to configure and launch the Rwf HTTP server. It includes setting up routes, initializing logging, and running the application. ```rust use rwf::http::{self, Server}; #[tokio::main] async fn main() -> Result<(), http::Error> { // Configure the logger. Logger::init(); // Define routes. let routes = vec![ route!("/" => index), ]; // Launch the HTTP server. Server::new(routes) .launch() .await } ``` -------------------------------- ### Install Rwf CLI Source: https://github.com/levkk/rwf/blob/main/docs/docs/models/migrations.md Installs the Rwf command-line interface tool using Cargo, which is necessary for managing migrations and other project setup tasks. ```shell cargo install rwf-cli ``` -------------------------------- ### Setup Stimulus Application with Custom Controllers (JavaScript) Source: https://github.com/levkk/rwf/blob/main/rwf-admin/templates/rwf_admin/head.html This snippet initializes a Stimulus application and registers two custom controllers: 'Requests' and 'Reload'. It imports necessary components from the Stimulus library and the custom controller files, then starts the application. This setup is crucial for enabling Stimulus's declarative behavior in the application. ```javascript import { Application } from "hotwired/stimulus"; const application = Application.start(); import Requests from "/static/rwf_admin/js/requests_controller.js"; import Reload from "/static/rwf_admin/js/reload_controller.js"; application.register("requests", Requests); application.register("reload", Reload); ``` -------------------------------- ### Create Rust Project with Cargo Source: https://github.com/levkk/rwf/blob/main/docs/docs/index.md Initializes a new Rust binary project using Cargo, the Rust package manager. This command sets up the basic project structure required for a web application. ```bash cargo init --bin rwf-web-app && cd rwf-web-app ``` -------------------------------- ### Rust: Start WebSocket Server Source: https://github.com/levkk/rwf/blob/main/docs/docs/controllers/websockets.md Illustrates how to start an Rwf server with WebSocket support by adding a WebSocket controller to the server routes. This example configures the server to listen for WebSocket connections at the `/websocket` path. Requires `rwf::prelude::*` and `rwf::http::{Server, http}`. ```rust use rwf::prelude::*; use rwf::http::{ Server, http }; #[tokio::main] async fn main() -> Result<(), http::Error> { let server = Server::new(vec![ route!("/websocket" => Echo), ]) .launch() .await } ``` -------------------------------- ### Rwf CLI Commands Overview Source: https://github.com/levkk/rwf/blob/main/docs/docs/models/migrations.md Displays the available commands and options for the Rwf CLI, providing an entry point to manage migrations, project setup, and get help. ```apidoc rwf-cli --help Rust Web Framework CLI Usage: rwf-cli Commands: migrate Manage migrations setup Setup the project for Rwf help Print this message or the help of the given subcommand(s) Options: -h, --help Print help -V, --version Print version ``` -------------------------------- ### Add Rwf Crate to Project Source: https://github.com/levkk/rwf/blob/main/docs/docs/index.md Adds the Rwf crate as a dependency to your Rust project's Cargo.toml file. This makes the Rwf framework available for use in your application. ```bash cargo add rwf ``` -------------------------------- ### Run the Application with Cargo Source: https://github.com/levkk/rwf/blob/main/examples/django/README.md Executes the application using the Cargo build tool. This command typically starts the Rust backend server which hosts the Django application. ```bash cargo run ``` -------------------------------- ### Run the Application Source: https://github.com/levkk/rwf/blob/main/examples/turbo/README.md Command to compile and run the Rust application using the Cargo build tool. ```rust cargo run ``` -------------------------------- ### Define Rwf Controller Source: https://github.com/levkk/rwf/blob/main/docs/docs/index.md Demonstrates how to define a simple asynchronous controller function using the `#[controller]` macro in Rwf. It returns an HTML response. ```rust use rwf::prelude::*; #[controller] async fn index() -> Response { Response::new().html("

My first Rwf app!

") } ``` -------------------------------- ### Create PostgreSQL Database Source: https://github.com/levkk/rwf/blob/main/examples/turbo/README.md Command to create the PostgreSQL database named 'rwf_turbo' required for the application. ```shell createdb rwf_turbo ``` -------------------------------- ### Up Migration Example Source: https://github.com/levkk/rwf/blob/main/docs/docs/models/migrations.md An example of an 'up' migration script that creates a 'users' table with an ID, email, and creation timestamp. ```sql CREATE TABLE users ( id BIGSERIAL PRIMARY KEY, email VARCHAR UNIQUE NOT NULL, created_at TIMESTAMPTZ NOT NULL DEFAULT NOW() ); ``` -------------------------------- ### Explaining Query Plans Source: https://github.com/levkk/rwf/blob/main/examples/orm/README.md Demonstrates how to get the query execution plan without actually running the query by using the `.explain()` method. This is helpful for performance analysis and optimization. ```rust let query_plan = User::all() .filter_lte("created_at", OffsetDateTime::now_utc()) .limit(25) .explain(&mut conn) .await?; println!("{}", query_plan); // Filter: (created_at <= '2024-10-09 10:23:31.561024-07'::timestamp with time zone) ``` -------------------------------- ### Install Rwf CLI with Cargo Source: https://github.com/levkk/rwf/blob/main/rwf-cli/README.md Installs the Rwf CLI tool globally using the Rust package manager, Cargo. After installation, ensure that `~/.cargo/bin/` is included in your system's PATH environment variable for the CLI to be accessible. ```shell $ cargo install rwf-cli ``` -------------------------------- ### PageController Login Example Source: https://github.com/levkk/rwf/blob/main/docs/docs/controllers/pages.md Illustrates using the `PageController` trait for a login page. The `async fn get` method handles rendering the login form, while `async fn post` processes form data, validates user credentials, and redirects the user upon successful login. ```rust use rwf::prelude::*; #[derive(Default, macros::PageController)] struct Login; impl PageController for Login { // Handle GET and show the login form. async fn get(&self, request: &Request) -> Result { render!(request, "templates/login.html") } // Handle POST, receive form data, check information, and // redirect the logged in user to a different page. async fn post(&self, request: &Request) -> Result { let form = request.form_data(); let email = form.get_required::("email"); let password = form.get_required::("password"); // Check that the user exists Ok(Response::new().login(user.id).redirect("/account")) } } ``` -------------------------------- ### Install Rwf Admin Source: https://github.com/levkk/rwf/blob/main/rwf-admin/README.md Demonstrates how to install the Rwf admin panel into an existing Rust application by adding it to routes and preloading templates at startup. Requires `rwf` and `rwf-admin` crates. ```rust use rwf::prelude::*; use rwf::http::{Server, Error}; #[tokio::main] async fn main() -> Result<(), Error> { rwf_admin::install()?; let mut routes = vec![]; // Add your routes... routes.extend(rwf_admin::routes()); Server::new(routes) .launch() .await } ``` -------------------------------- ### Create Python Virtual Environment Source: https://github.com/levkk/rwf/blob/main/examples/django/README.md Creates a new Python virtual environment named 'venv'. This isolates project dependencies from the global Python installation, ensuring a clean and reproducible build environment. ```bash python3 -m venv venv ``` -------------------------------- ### Basic Rwf Application Setup Source: https://github.com/levkk/rwf/blob/main/rwf/README.md This Rust code snippet demonstrates how to set up a minimal Rwf web application. It defines a simple controller function that returns an HTML response and configures the server to listen for requests on the root path. ```rust use rwf::prelude::*; use rwf::http::Server; #[controller] async fn index() -> Response { Response::new().html("

Welcome to Rwf!

") } #[tokio::main] async fn main() { Server::new(vec![ route!("/" => index), ]) .launch() .await .unwrap(); } ``` -------------------------------- ### Rwf TOML Configuration Structure Source: https://github.com/levkk/rwf/blob/main/docs/docs/configuration.md Illustrates the structure and common settings within the `rwf.toml` configuration file, including sections for general application settings and database connection parameters. ```toml # Example rwf.toml configuration [general] host = "0.0.0.0" port = 8000 log_queries = false secret_key = "YOUR_BASE64_SECRET_KEY" cache_templates = false csrf_protection = true max_request_size = "5MB" [database] name = "mydatabase" user = "myuser" url = "postgresql://user:password@host:port/database_name" checkout_timeout = 5000 idle_timeout = 3600000 ``` -------------------------------- ### List Users Output Example Source: https://github.com/levkk/rwf/blob/main/docs/docs/controllers/REST/model-controller.md Example JSON output for a request to list users, showing user objects with their properties. ```json [ {"id": 1, "email": "admin@example.com", "admin": true}, {"id": 2, "email": "alice1@example.com", "admin": false} ] ``` -------------------------------- ### Serve Static Files in RWF Source: https://github.com/levkk/rwf/blob/main/docs/docs/controllers/static-files.md This example demonstrates how to integrate the RWF `StaticFiles` controller into your application's server setup. It configures the server to serve files from the 'static' directory under the '/static' route, automatically handling MIME types based on file extensions. The `StaticFiles` controller is added to the `Server` during initialization. ```rust use rwf::controller::StaticFiles; use rwf::http::{Server, self}; #[tokio::main] async fn main() -> Result<(), http::Error> { let server = Server::new(vec![ StaticFiles::serve("static")?, ]) .launch() .await; Ok(()) } ``` -------------------------------- ### SQL Query Example Source: https://github.com/levkk/rwf/blob/main/examples/orm/README.md An example SQL query generated by the ORM for fetching a record by its primary key. ```sql SELECT * FROM users WHERE id = 15; ``` -------------------------------- ### PageController for GET and POST Source: https://github.com/levkk/rwf/blob/main/examples/quick-start/README.md Illustrates using the `PageController` trait to handle different HTTP methods (GET, POST) within a single controller. The `get` method handles GET requests, and the `post` method handles POST requests, simplifying form submissions. ```rust use rwf::controllers::PageController; use rwf::prelude::*; #[derive(rwf::macros::PageController)] struct SignupController; #[async_trait] impl PageController for SignupController { async fn get(&self, request: &Request) -> Result { Ok(Response::new().html(r#"
<%= csrf_token() %>