vial 0.0.0

a micro micro-framework
Documentation

~ vial: a micro micro-framework ~

vial is a small web "framework" for making small web "sites".

It includes but a droplet of the bare minimum:

  • Parsing and routing HTTP requests
  • Handling POST requests
  • Serving static files (css, js)

Everything else... well, that's up to you.

The goal is a small, simple, as-few-as-possible-dependencies web library you can use to test out an idea quickly or get a static site rolling. Single file, server side apps? Yes, please!

It's sort of like a picnic where the playlist is all 90s music and you have to bring your own beverage. Yabba dabba doo!

~ hello world ~

As is tradition... the bare minimum:

use vial::vial;

vial! {
    GET "/" => |_| "Hello, world!".into();
}

fn main() {
    if let Err(e) = vial::run!("0.0.0.0:7667") {
        eprintln!("error: {}", e);
    }
}

For a bit more sanity, you can route to functions directly:

use vial::{vial, Request, Response};

vial! {
    GET "/hi/world" => |_| "Hello, world!".into();
    GET "/" => echo;
}

fn echo(req: Request) -> Response {
  Response::from(
    format!("You said: <b>{}</b>", req.params("echo").unwrap())
  )
}

fn main() {
    if let Err(e) = vial::run!("0.0.0.0:7667") {
        eprintln!("error: {}", e);
    }
}

~ bonus features ~

vial doesn't come with JSON or a template engine or any of that fancy stuff, but there are a few compile-time features you can activate for enhanced productivity:

  • cookies: Cookie monster!
  • markdown: Add Markdown rendering capabilities.
  • json: to_json and from_json powers, via Serde.
  • tera: Templating, via Tera.
  • htxl: Vial's preferred, no-dependency template library: HTXL.
  • ssl: Add support for SSL/TLS. Normally you should be using a proxy.

~ T0DO ~

  • GET requests
  • POST requests
  • static file
  • static file etag
  • parse headers()
  • test headers()
  • test GET param()
  • test POST param()
  • test static file
  • test etag
  • multiple modules
  • before_filter
  • after_filter