vial
is a small web "framework" for making small web "sites".
It only includes a few basics:
Everything else... well, that's up to you.
The goal is an as-few-as-possible-dependencies web library you can use to test out an idea quickly or get a personal project rolling. Single file, server side apps? You bet! Fast compilation? Yes please! À la carte dependencies? Now you're talkin'!
It's sort of like a picnic where the playlist is all 90s music and you have to bring your own beverage. And food.
To get started, just add vial
to your Cargo.toml
:
toml
[dependencies]
vial = "*"
As is tradition:
```rust vial::routes! { GET "/" => |_| "Hello, world!"; }
fn main() { vial::run!().unwrap(); } ```
For a bit more sanity, you can route to functions directly:
```rust use vial::prelude::*;
routes! { GET "/echo" => echo; POST "/echo" => post; }
fn echo(_: Request) -> &'static str { "
" }fn post(req: Request) -> String { format!( "
fn main() { vial::run!().unwrap(); } ```
To really break the mold, you can split your site into different modules:
```rust use vial;
mod wiki; mod blog;
mod index { use vial::prelude::*; routes! { GET "/" => || Response::fromfile("index.html") } }
fn main() {
// The order matters here - if wiki
and blog
both define "/",
// the mod index
version will match first and get run.
vial::run!(index, wiki, blog);
}
```
But hey, who wants to putz around with HTML when you can be writing
Rust? Enable the horror
feature and you're on your way:
```rust use vial::prelude::*;
routes! { GET "/" => |_| html! { p { : "You're looking for this: "; a(href="/echo") { : "echo" } } }; GET "/echo" => echo; POST "/echo" => post; }
fn echo(_: Request) -> impl Responder { html! { form(method="POST") { p { : "Type something: "; input(type="text", name="echo"); input(type="submit"); } } } }
fn post(req: Request) -> impl Responder { ownedhtml! { h1: req.form("echo") .unwrapor("You didn't say anything!"); } }
fn main() { vial::run!().unwrap(); } ```
Install [cargo-watch]:
$ cargo install cargo-watch
$ cargo watch -x 'run --example hello_world'
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:
to_json
and from_json
powers, via Serde.Please note: The list above is a work-in-progress.
before_filter