3 releases
0.2.2 | Sep 30, 2023 |
---|---|
0.2.1 | Sep 18, 2023 |
0.2.0 | Sep 16, 2023 |
#200 in #site
22 downloads per month
40KB
683 lines
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
- 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.
- 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.
- 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
}
Dependencies
~16–28MB
~490K SLoC