### Setup RustF Project using Git Template Source: https://github.com/numerum-tech/rustf/blob/main/book/src/getting-started/installation.md Clones the RustF sample application repository and copies its contents to a new project directory. This provides a pre-configured starting point for development. ```bash # Clone the repository git clone https://github.com/numerum-tech/rustf.git cd rustf/sample-app # Copy to your project cp -r . /path/to/your/project cd /path/to/your/project # Install dependencies and run cargo run ``` -------------------------------- ### Manual RustF Project Setup: src/controllers/home.rs Source: https://github.com/numerum-tech/rustf/blob/main/book/src/getting-started/installation.md Defines a basic controller for the RustF application. This example sets up a GET route for the root path ('/') that returns an HTML response. ```rust use rustf::prelude::*; pub fn install() -> Vec { routes![ GET "/" => index, ] } async fn index(ctx: &mut Context) -> Result<()> { ctx.html("

Hello, RustF!

") } ``` -------------------------------- ### Manual RustF Project Setup: Cargo New Source: https://github.com/numerum-tech/rustf/blob/main/book/src/getting-started/installation.md Initializes a new Rust project using Cargo and navigates into the project directory. This is the first step for manual RustF setup. ```bash cargo new my-app cd my-app ``` -------------------------------- ### Minimal TOML Configuration Example Source: https://github.com/numerum-tech/rustf/blob/main/book/src/guides/configuration.md Presents a basic TOML configuration file for a RustF application, demonstrating the minimal setup required for server port and database URL, relying on default values for other settings. ```toml # config.toml - Minimal configuration using defaults [server] port = 3000 [database] url = "postgresql://localhost/myapp" ``` -------------------------------- ### Simple Home Controller Example Source: https://github.com/numerum-tech/rustf/blob/main/book/src/guides/controllers.md Provides a complete example of a controller file (`src/controllers/home.rs`) demonstrating how to define routes and handler functions for the home page, about page, and contact page. ```APIDOC ## Simple Home Controller Example ### Description An example controller file (`src/controllers/home.rs`) that defines routes for the home, about, and contact pages using the `routes!` macro and renders views with JSON data. ### Method GET ### Endpoint - `/` - `/about` - `/contact` ### Parameters None ### Request Body None ### Request Example ```rust // src/controllers/home.rs use rustf::prelude::*; pub fn install() -> Vec { routes![ GET "/" => index, GET "/about" => about, GET "/contact" => contact, ] } async fn index(ctx: &mut Context) -> Result<()> { let data = json!({ "title": "Welcome to RustF", "message": "Your application is running successfully!", "features": [ "Auto-discovery for controllers", "Template engine with layouts", "Session management", "Built-in security features" ] }); ctx.view("/home/index", data) } async fn about(ctx: &mut Context) -> Result<()> { let data = json!({ "title": "About", "description": "Built with RustF framework - an AI-friendly MVC framework for Rust", "version": "1.0.0" }); ctx.view("/home/about", data) } async fn contact(ctx: &mut Context) -> Result<()> { ctx.view("/home/contact", json!({ "title": "Contact Us", "email": "info@example.com" })) } ``` ### Response #### Success Response (200) - **`view`** (string) - Path to the view template. - **`data`** (JSON) - Data to be passed to the view. #### Response Example (View rendering depends on the template engine and data provided. Example for `/` endpoint): ```json { "title": "Welcome to RustF", "message": "Your application is running successfully!", "features": [ "Auto-discovery for controllers", "Template engine with layouts", "Session management", "Built-in security features" ] } ``` ``` -------------------------------- ### RustF Application Lifecycle Setup Source: https://github.com/numerum-tech/rustf/blob/main/book/book/guides/controllers.html Shows the basic setup and startup of a RustF application. It demonstrates how to initialize the application, register controllers, add middleware, and start the HTTP server. ```rust #![allow(unused_variables)] #fn main() { // 1. Application setup let app = RustF::new() .controllers(auto_controllers!()) // Register all controllers .middleware("auth", AuthMiddleware::new()); // Add middleware // 2. Server startup app.start().await; // Starts HTTP server // 3. Request processing // HTTP Request -> Middleware Chain -> Controller Handler -> HTTP Response #} ``` -------------------------------- ### Rust: Import and Use RustF Utilities Source: https://github.com/numerum-tech/rustf/blob/main/book/src/api-reference/utilities.md Demonstrates how to import the RustF prelude or the U module to access utility functions. Shows examples of direct and namespaced access for common tasks like generating GUIDs, encoding strings, getting HTTP status text, and hashing data. ```rust use rustf::prelude::*; // or use rustf::U; // Direct access - commonly used functions let id = U::guid(); let encoded = U::encode("hello world"); let status = U::http_status(404); // "Not Found" let hash = U::sha256("data"); // Secure hash function // Namespaced access - extended functionality let slug = U::String::to_slug("Hello World!"); let html = U::Encoding::html_encode("