- Notifications
You must be signed in to change notification settings - Fork44
A lightweight web framework built on hyper, implemented in Rust language.
License
miketang84/sapper
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Sapper, a lightweight web framework, written in Rust.
Sapper focuses on ergonomic usage and rapid development. It can work withstable Rust.
Sapper now is based on hyper 0.10.13.
Look intojson demo, you can learn how to parse http parameters, and return json;
Look intomvc diesel demo, you can learn how to use database, how to render template, and how to redirect.
In Cargo.toml,
[dependencies]sapper = "0.1"
Now, you can boot the example server with:
cd examples/basic/cargo buildcargo run
and open the browser, visit
http://localhost:1337/
or
http://localhost:1337/test
or any other url to test it.
more continued...
mike@mike-Vostro-3653:~/works2/wrk$ uname -aLinux mike-Vostro-3653 4.10.0-21-generic #23-Ubuntu SMP Fri Apr 28 16:14:22 UTC 2017 x86_64 x86_64 x86_64 GNU/Linuxmike@mike-Vostro-3653:~/works2/wrk$ cat /proc/cpuinfo processor: 0vendor_id: GenuineIntelcpu family: 6model: 94model name: Intel(R) Core(TM) i3-6100 CPU @ 3.70GHzcpu MHz: 832.183cache size: 3072 KBbogomips: 7392.00...mike@mike-Vostro-3653:~/works2/sapper/examples/tiny$ cargo run --release Finished release [optimized] target(s) in 36.27 secs Running `target/release/tiny`Listening on http://127.0.0.1:1337output: hello, world!mike@mike-Vostro-3653:~/works2/wrk$ ./wrk -t2 -c100 -d30s http://127.0.0.1:1337Running 30s test @ http://127.0.0.1:1337 2 threads and 100 connections Thread Stats Avg Stdev Max +/- Stdev Latency 21.73us 139.92us 16.02ms 99.87% Req/Sec 235.94k 26.75k 259.73k 76.33% 7045973 requests in 30.04s, 598.04MB readRequests/sec: 234536.10Transfer/sec: 19.91MB
- Sapper supplies only basic framework;
- Three level granularity (global, module, function handler) middleware controller and unified middleware presentation;
- Typesafe abstraction, keep the same spirit with hyper;
- For easy using, will supply some convenient macros to help write business logics;
- Global object cross requests;
Typed, hierarchical control, and middlewares.
In Sapper, nearly every important thing is aType
. They are:
- Each module is a type, different modules are different types;
- Every middleware supplies some (0 to n) types for handler getting values;
- Inherited from hyper's typed spirit, all headers, mime and so on should use types for manipulation.
- Sapper forces you to put router in each module (in main.rs, you can not write it, no space left for you to write);
- Sapper forces you to seperate the router binding and the handler realization;
- Sapper's plugin processor can be used in app level wrapper, module level wrapper, and each handler. These three level hierarchical controls make it flexible to construct your business.
Sapper's core contains only router system, request and response definitions, middleware system, and some other basic facilities. Nearly all practical features, such as query parameter, body parameter, cookie, session, json, xml, orm..., are supplied by the corresponding middlewares.
Sapper's middleware is very easy to write. One rust module realized a function on the prototype of
fn(&mutRequest) ->Result<()>;// before pluginfn(&Request,&mutResponse) ->Result<()>;// after plugin
can be thought as Sapper's middleware. Sample middleware:sapper_query.
- QueryParams (x-www-form-urlencoded);
- BodyParams (x-www-form-urlencoded);
- BodyJsonParams;
- Basic static file serving for dev;
- Global object shared cross requests;
- Macros;
- Multipart;
- sapper_query parsing query string for req;
- sapper_body parsing body parameters for req, including url form encoded, json type, json to struct macro;
- sapper_logger record request and caculate its time;
- sapper_session a cookie plugin, and else supply a helper set_cookie function;
- sapper_tmpl use tera to render template;
Thanks to these projects below:
- hyper Sapper is based on hyper mio branch;
- iron Sapper learns many designs from iron;
- router Sapper steals router about code from it;
- recognizer Sapper uses this route recognizer;
MIT
About
A lightweight web framework built on hyper, implemented in Rust language.
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors5
Uh oh!
There was an error while loading.Please reload this page.