velto

Crates.iovelto
lib.rsvelto
version1.9.0
created_at2025-08-17 10:37:48.78262+00
updated_at2025-10-26 20:42:19.243288+00
descriptionVelto: expressive, async-native, and grounded Rust framework
homepage
repositoryhttps://github.com/pjdur/velto
max_upload_size
id1799303
size82,200
Pjdur (Pjdur)

documentation

https://docs.rs/velto

README

๐Ÿš€ Velto

A minimal async web framework for Rust, built for clarity, speed, and joy.

Crates.io GitHub Actions Workflow Status Docs.rs License: MIT


โœจ Features

  • ๐Ÿงญ Intuitive routing with route!(...) and route_any!(...) macros
  • ๐Ÿงต Templating with render!, {% include %}, and {% extends %} support
  • โšก Fully async, powered by async_tiny
  • ๐Ÿ”„ LiveReload support in development mode
  • ๐Ÿ“ Static file serving with zero config
  • ๐Ÿ”Œ Global middleware support via App::use_middleware()
  • ๐Ÿง  Minimal boilerplate via velto::prelude
  • ๐Ÿงช Built-in testing with TestRequest
  • ๐Ÿ›  First-class CLI support via velto-cli

๐Ÿ“ฆ Installation

Add Velto to your Cargo.toml:

[dependencies]
velto = "1.9.0"

Or use velto-cli to scaffold a new project instantly:

cargo install velto-cli
velto new my-app
cd my-app
velto run

๐Ÿš€ Quick Start

use velto::prelude::*;
use velto::middleware::logger; // Built-in middleware

fn homepage(_req: &Request) -> Response {
    render!("index.html", {
        "title" => "Welcome to Velto",
        "message" => "Fast. Clean. Rusty."
    })
}

#[tokio::main]
async fn main() -> std::io::Result<()> {
    let mut app = App::new();
    app.use_middleware(logger); // Add middleware
    app.enable_dev_mode();      // Enables LiveReload
    route!(app, "/" => homepage);
    app.serve_static("static");
    app.run("127.0.0.1:8080").await
}

๐Ÿ”Œ Middleware

Velto supports global middleware functions that run before and/or after route handlers.
Use App::use_middleware() to register middleware like logging, authentication, or header injection.

Example: Logger Middleware

pub fn logger(req: &Request, next: &dyn Fn(&Request) -> Response) -> Response {
    println!("๐Ÿ“ฅ {} {}", req.method(), req.url());
    let res = next(req);
    println!("๐Ÿ“ค Responded with {}", res.status_code());
    res
}
  • Middleware is synchronous and composable
  • Multiple middleware are executed in registration order
  • Built-in logger middleware is available in velto::middleware

๐Ÿ”„ LiveReload

Velto automatically watches your static/ and templates/ directories in dev mode.
When a file changes, connected browsers reload instantly via WebSocket.

No setup required. Just call:

app.enable_dev_mode();

๐Ÿงช Testing

Velto includes a built-in TestRequest type for simulating requests in unit tests:

#[test]
fn test_homepage() {
    let mut app = App::new();
    route!(app, "/" => |_req| {
        Response::from_string("Hello, test!")
    });

    let res = velto::test::TestRequest::new("GET", "/").send(&app);
    assert_eq!(res.status_code(), 200);
    assert!(res.body().contains("Hello"));
}

No external test harness required โ€” just write Rust tests and run cargo test.


๐Ÿงฐ Project Structure

Velto is organized into modular components for clarity and maintainability:

velto/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ app.rs           # Core application logic
โ”‚   โ”œโ”€โ”€ dev.rs           # Dev mode toggles and helpers
โ”‚   โ”œโ”€โ”€ form.rs          # Form data parsing
โ”‚   โ”œโ”€โ”€ http_method.rs   # HTTP method utilities
โ”‚   โ”œโ”€โ”€ macros.rs        # Macros for render! and route!
โ”‚   โ”œโ”€โ”€ middleware.rs    # Middleware system and built-in examples
โ”‚   โ”œโ”€โ”€ prelude.rs       # Public API surface
โ”‚   โ”œโ”€โ”€ reload.rs        # LiveReload WebSocket + file watcher
โ”‚   โ”œโ”€โ”€ response.rs      # HTTP response utilities including redirect helpers
โ”‚   โ”œโ”€โ”€ router.rs        # Routing and handler dispatch
โ”‚   โ”œโ”€โ”€ template.rs      # Templating engine with include/inheritance
โ”‚   โ”œโ”€โ”€ test.rs          # TestRequest and internal test harness
โ”‚   โ”œโ”€โ”€ util.rs          # Utility functions (e.g., MIME types)
โ”‚   โ””โ”€โ”€ lib.rs           # Entry point

โ“ Why Velto

Velto is for developers who want:

  • A fast, async-native web framework without the complexity of full-stack giants
  • Clean routing and templating without ceremony
  • Instant LiveReload for a smooth development loop
  • A modular codebase that grows with your project
  • A framework that feels like Rust โ€” not like a port of something else

Whether you're building a personal site, a microservice, or a dev tool, Velto gives you just enough structure to stay productive โ€” and just enough freedom to stay creative.


๐Ÿ” Migration from 0.x

Velto 1.0.0 introduced async support and LiveReload, but kept the public API familiar. Here's what changed:

Old (0.x) New (1.0.0)
fn main() #[tokio::main] async fn main()
Response<Cursor<Vec<u8>>> Response (no generics)
app.run(...) app.run(...).await
No LiveReload app.enable_dev_mode()

Most route handlers and macros (route!, render!) remain unchanged.
Just update your main() function and remove Cursor<Vec<u8>> from response types.


๐Ÿ“„ License

MIT โ€” free to use, modify, and distribute.


๐Ÿ’ฌ Contributing

Velto is evolving rapidly. If you have ideas, feedback, or want to help shape its future, open an issue or submit a PR.
We welcome clean code, thoughtful design, and good vibes.

Commit count: 27

cargo fmt