web-base

Crates.ioweb-base
lib.rsweb-base
version0.2.2
sourcesrc
created_at2023-09-16 15:34:47.981287
updated_at2023-09-30 13:02:37.490354
descriptioncollection of utilities and configurations for building web applications
homepagehttps://git.hydrar.de/jmarya/web-base
repositoryhttps://git.hydrar.de/jmarya/web-base
max_upload_size
id974407
size91,420
Juan Miguel Angelo Rodriguez y Alvarez (JMARyA)

documentation

README

web-base

web_base is an open-source Rust crate designed to simplify web application development by providing a collection of utilities and configurations for building web applications.

Features

  1. Site Configuration: web_base provides a Site struct that allows you to configure various aspects of your web application, including:
    • Bootstrap Styling: Enable or disable Bootstrap styling for your site.
    • CSRF Protection: Enable or disable Cross-Site Request Forgery (CSRF) protection functions.
    • PicoCSS Support: Enable or disable the use of PicoCSS for lightweight CSS handling.
    • htmx Integration: Enable or disable htmx for enhancing interactivity.
    • Content Scaling: Enable or disable content scaling for different screen sizes.
    • Favicon Configuration: Set the URL for the site's favicon.
    • Custom Head Content: Add custom HTML content to the <head> section of your web pages.
  2. Utilities: web_base offers a set of utility functions to simplify common web development tasks:
    • Parsing Query Strings: Easily parse query strings into key-value pairs.
    • Detecting Browsers: Check if an incoming request is from a web browser.
    • Detecting Onion and I2P Traffic: Identify requests originating from Onion and I2P networks.
    • Dynamic Link Generation: Generate links based on the request's origin, allowing for flexible link handling.
  3. Based on Actix Web: The map! macro simplifies the process of creating an Actix Web HTTP server with specific configurations and middleware. It automatically sets up various server configurations based on the Site configuration, making it easier to create your Actix Web server.

Examples

web_base provides several examples and use cases for its features. Check the documentation and code examples to see how to leverage this library for your web application needs.

Getting Started

To use this crate in your project, you have to add tokio and actix-web to your Cargo.toml.

Run some examples from examples directory or use this as a base:

use actix_web::{get, HttpRequest, Responder};
use maud::html;

#[get("/")]
pub(crate) async fn index(r: HttpRequest) -> impl Responder {
    let content = html!(
        p { "Hello World" };
    )
    .into_string();
    web_base::func::build_site(&r, "Index", &content)
}

#[actix_web::main]
async fn main() -> std::io::Result<()> {
    web_base::map!(
        web_base::Site::new()
            .enable_bootstrap(false)
            .enable_picocss(false),
        |app: actix_web::App<_>| { app.service(index) }
    )
    .bind(("0.0.0.0".to_string(), 8080))?
    .run()
    .await
}
Commit count: 0

cargo fmt