ProductPromotion
Logo

Rust

made by https://0x3d.site

GitHub - miketang84/sapper: A lightweight web framework built on hyper, implemented in Rust language.
A lightweight web framework built on hyper, implemented in Rust language. - miketang84/sapper
Visit Site

GitHub - miketang84/sapper: A lightweight web framework built on hyper, implemented in Rust language.

GitHub - miketang84/sapper: A lightweight web framework built on hyper, implemented in Rust language.

Sapper

Sapper, a lightweight web framework, written in Rust.

Sapper focuses on ergonomic usage and rapid development. It can work with stable Rust.

Sapper now is based on hyper 0.10.13.

Tutorial

Look into json demo, you can learn how to parse http parameters, and return json;

Look into mvc diesel demo, you can learn how to use database, how to render template, and how to redirect.

English Tutorial

中文教程

Import

In Cargo.toml,

[dependencies]
sapper = "0.1"

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 x86_64 x86_64 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

  • 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;

Philosophy

Typed, hierarchical control, and middlewares.

Typed

In Sapper, nearly every important thing is a Type. 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.

Hierarchical Control

  • 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.

Middlewares

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 (&mut Request) -> Result<()>;  // before plugin
fn (&Request, &mut Response) -> Result<()>; // after plugin

can be thought as Sapper's middleware. Sample middleware: sapper_query.

TODO

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

Middlewares

  • 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;

Related Projects

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;

License

MIT

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory