Sapper

Sapper, a lightweight web framework, written in Rust.

Sapper focuses on easy of use. It can work with stable Rust (>= 1.17).

Basic Example

Now, you can boot the example server with:

cd examples/basic/ cargo build cargo run

and open the browser, visit

http://localhost:1337/

or

http://localhost:1337/test

or any other url to test it.

Other Examples

  1. tiny
  2. init_global
  3. query params
  4. body params
  5. session
  6. template rendering
  7. simple logger
  8. response json
  9. mvc diesel demo

  10. more continued...

Basic Benchmark

``` mike@mike-Vostro-3653:~/works2/wrk$ uname -a Linux mike-Vostro-3653 4.10.0-21-generic #23-Ubuntu SMP Fri Apr 28 16:14:22 UTC 2017 x8664 x8664 x86_64 GNU/Linux

mike@mike-Vostro-3653:~/works2/wrk$ cat /proc/cpuinfo processor : 0 vendor_id : GenuineIntel cpu family : 6 model : 94 model name : Intel(R) Core(TM) i3-6100 CPU @ 3.70GHz cpu MHz : 832.183 cache size : 3072 KB bogomips : 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:1337

output: hello, world!

mike@mike-Vostro-3653:~/works2/wrk$ ./wrk -t2 -c100 -d30s http://127.0.0.1:1337 Running 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 read Requests/sec: 234536.10 Transfer/sec: 19.91MB ```

Features

Philosophy

Sapper's philosophy is plugined, typed, hierarchical control.

Plugined

Sapper's core contains only middleware/plugin system, router system, request and response definitions, and some other basic facilities. Nearly all practical features, such as query parameter, body parameter, cookie, session, json, xml, orm..., are supplied by the outer plugins.

Sapper's plugin is very easy to write. One rust module realized a function on the prototype of

rust fn (&mut Request) -> Result<()>; // before plugin fn (&Request, &mut Response) -> Result<()>; // after plugin

can be thought as Sapper's plugin. Sample template please refer sapper_query plugin.

Typed

In Sapper, nearly every important thing is a Type. They are:

Hierarchical Control

TODO

  1. [X] QueryParams (x-www-form-urlencoded);
  2. [X] BodyParams (x-www-form-urlencoded);
  3. [X] BodyJsonParams;
  4. [X] Basic static file serving for dev;
  5. [X] Global object shared cross requests;
  6. [X] Macros;
  7. [ ] Multipart;

Plugins

Components

Related Projects

Thanks to these projects below:

License

MIT