- Notifications
You must be signed in to change notification settings - Fork14
🧪 a micro micro-framework for rust
License
Apache-2.0, MIT licenses found
Licenses found
xvxx/vial
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Vial is a small web "framework" for making small web sites inRust.
It includes just a few basics:
- Parsing and routing HTTP requests
- Parsing POST form data
- Serving static files (css, js)
Everything else... well, that's up to you.
The goal is an as-few-as-possible-dependencies web library you canuse to test out an idea quickly or get a personal projectrolling.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 youhave to bring your own beverages. And food.
To learn more, keep reading or visit one of these links:
⚠ Status: Vial is still in development and shouldn't be used tobuild real world apps on untrusted networks. Please proceed with cautionand wear a hard hat at all times.
To get started, just addvial
to yourCargo.toml
:
[dependencies]vial ="0.1"
Now you canuse vial::prelude::*;
in your application to pull in thecommon types, or just use the crate like any other.
As is tradition:
vial::routes!{GET"/" => |_|"Hello, world!";}fnmain(){ vial::run!().unwrap();}
For a bit more sanity, you can route to functions directly:
use vial::prelude::*;routes!{GET"/echo" => echo;POST"/echo" => post;}fnecho(_:Request) ->&'staticstr{"<form method='POST'> <input type='text' name='echo'/> <input type='submit'/> </form>"}fnpost(req:Request) ->String{format!("<h1>You said: {}</h1>", req.form("echo").unwrap_or("You didn't say anything!"))}fnmain(){ vial::run!().unwrap();}
Toreally break the mold, you can split your site into differentmodules:
use vial;mod wiki;mod blog;mod index{use vial::prelude::*;routes!{GET"/" => |_|Response::from_file("index.html")}}fnmain(){// 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 writingRust? Enable thehorror
feature and you're on your way:
use vial::prelude::*;#[macro_use]externcrate horrorshow;routes!{GET"/" => |_| html!{ p{:"You're looking for this: "; a(href="/echo"){:"echo"}}};GET"/echo" => echo;POST"/echo" => post;}fnecho(_:Request) ->implResponder{html!{ form(method="POST"){ p{:"Type something: "; input(type="text", name="echo"); input(type="submit");}}}}fnpost(req:Request) ->implResponder{owned_html!{ h1: req.form("echo").unwrap_or("You didn't say anything!");}}fnmain(){ vial::run!().unwrap();}
vial doesn't come with JSON or a template engine or any of thatfancy stuff by default, but there (will be) a few compile-time--features
you can activate for enhanced productivity:
- hatter: EnableHatter: A positively mad, HTML templatinglanguage.
- horror: Enablehorrorshow: A small & fast macro-based HTMLbuilder.
- json_serde:
Request::json
andResponse::with_json
powers, viaSerde. - json_nano:
Request::json
andResponse::with_json
, viananoserde. - cookies:
Request::cookie()
,Response::with_cookie
, andfriends. - sessions:
Request::session()
,Response::with_session
, andfriends. - uploads: Multipart form data (file uploads)
- log: Access logging
Please note: The list above is a work-in-progress.
Your assets will automatically get reloaded in debug mode, completewith proper ETag support, but you probably want to refresh your Rustcode, too.
Right now the easiest way is to usecargo-watch:
$ cargo install cargo-watch$ cargo watch -x 'run --example hello_world'
Tests can be run on a recent version of stableRust withmake test
. We also run tests on commits withGitHubActions.
Vial prefers to put everything intests/
rather than includetests directly insrc/*.rs
files. To access private APIs in tests,we make thempub
and use#[doc(hidden)]
. Your cooperation isappreciated.
Vial is licensed under either of the following, at your option:
- Apache License, Version 2.0, (LICENSE-APACHE orhttp://www.apache.org/licenses/LICENSE-2.0)
- MIT License (LICENSE-MIT orhttp://opensource.org/licenses/MIT)
About
🧪 a micro micro-framework for rust
Topics
Resources
License
Apache-2.0, MIT licenses found
Licenses found
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors10
Uh oh!
There was an error while loading.Please reload this page.