• Stars
    star
    617
  • Rank 72,724 (Top 2 %)
  • Language
    Rust
  • License
    MIT License
  • Created over 8 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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 Repositories

1

bamboo

Bamboo is the web framework of Lua based on Mongrel2, ZeroMQ and NoSQL database.
Lua
229
star
2

forustm

A rust forum.
Rust
58
star
3

jikeshijian

Practice code for the course of jikeshijian 《Rust语言从入门到实战》
Rust
41
star
4

rusoda

Rusota is a rust implemented Forum/Blog/CMS system.
Rust
40
star
5

learn-rust

Learn rust works.
Rust
22
star
6

sapper_examples

sapper examples
Rust
22
star
7

lglib

The basic extended lua libraries for legerobot's all products
Lua
11
star
8

superpoll

superpoll - a rust async runtime extends futures strictly, rather than rewrite many things.
Rust
9
star
9

wumn

Wumn is a thin abstract ORM over SQL and Rust types.
Rust
9
star
10

substrate-highlevel-course

substrate-highlevel-course
Rust
9
star
11

sporm

An easy orm for rust.
Rust
8
star
12

bamboo_doc_cn

The documents of Bamboo web framework for Chinese.
7
star
13

candle_demo_openchat_35

candle_demo_openchat_35
Rust
7
star
14

bamboo-redis

bamboo redis is the combination of redis-lua and lua-hiredis
Lua
6
star
15

eightfish

A framework for openweb
Rust
5
star
16

monserver

a web server based on mongrel2.
C
5
star
17

axumapp_stepbystep

axumapp_stepbystep
Rust
4
star
18

sapper_std

sapper macro helpers
Rust
4
star
19

learn-async-tokio

learn-async-tokio
Rust
4
star
20

subforum

A Web3.0 forum implemented based on Substrate
Rust
4
star
21

jedrc

my .jedrc
3
star
22

panda-rs

The GUI toolkit for rust based on Servo.
2
star
23

mttester-rs

Rust http logic tester, easy to use.
Rust
2
star
24

event_listener

listen event from substrate
Rust
2
star
25

attendmqtt

Rust
2
star
26

learn-libp2p

libp2p learning and examples
Rust
2
star
27

openforum-subnode

openforum substrate node component
Rust
2
star
28

spcodegen

Sporm code generator.
Rust
2
star
29

oneblockplus_offchain_lesson

oneblockplus_offchain_lesson
Rust
2
star
30

discux

A frontend app for forums, connecting to the GUTP data backend.
Rust
2
star
31

bevy_snake_stepbystep

bevy_snake_stepbystep
Rust
2
star
32

tauriapp_stepbystep

tauriapp_stepbystep
Rust
1
star
33

bamboo-plugin-pagination

pagination plugin for bamboo framework.
Lua
1
star
34

mongol

lua driver to mongodb, prototype.
Lua
1
star
35

slint-chatbot-demo

rust+slint+candle+openchat3.5 demo
Rust
1
star
36

sapper_auth

plugin for implement http basic auth
1
star
37

sptool

a tool for communicate via serial port.
Rust
1
star
38

cryptopals

exercises
Rust
1
star
39

lgcms

LegeCMS is a cms lib on top of the bamboo framework.
Lua
1
star
40

blogrs

A Rust blog framework (based on rusoda).
Rust
1
star
41

tryew

The first yew project.
Rust
1
star
42

download_tool

A download tool for tasks.
Rust
1
star
43

bamboo-plugin-board

board plugin for bamboo.
Lua
1
star
44

bamboo-plugin-slide

slide plugin for bamboo.
Lua
1
star
45

my-first-substrate-test

my-first-substrate-test
Rust
1
star
46

ta_config

Textadept's configurations
Lua
1
star
47

lgstring

lglib's string part's C implementation
C
1
star
48

monserver-lua

the lua driver for monserver
Lua
1
star
49

sapper_tmpl

sapper template view module.
Rust
1
star
50

lgserver-node

a simplified lgserver implementation using node.
JavaScript
1
star
51

subpub_dispatcher

sub and pub dispatcher.
Lua
1
star
52

bamboo-plugin-rapidupload

rapid upload plugin for bamboo framework.
Lua
1
star
53

jmacs_config

My jmacs editor configurations
Ruby
1
star
54

lgcron

lgcron is a cron like daemon tool.
Lua
1
star
55

st-rs

Simple Terminal written by Rust, for general and embeded board usage.
Rust
1
star
56

bamboo-plugin-managetable

manage table plugin for bamboo framework.
Lua
1
star
57

bamboo_plugins

plugins for bamboo web framework
JavaScript
1
star
58

openforum

An open web forum program
Rust
1
star
59

sapper_logger

sapper request basic logger
Rust
1
star
60

yewapp_stepbystep

yewapp_stepbystep
Rust
1
star
61

sapper_session

sapper cookie plugin
Rust
1
star
62

misctools

some misc tools collection
C
1
star
63

bamvit

Bamboo on luvit.
1
star
64

candle_demo_yolov8

candle_demo_yolov8
Rust
1
star
65

bamboo-plugin-levelink

levelink plugin for bamboo framework.
Lua
1
star
66

sapper_body

body params plugin for sapper web framework.
Rust
1
star
67

bamboo-plugin-xheditor

xheditor plugin for bamboo framework.
JavaScript
1
star
68

learn-rust-lib

learn rust lib usages.
Rust
1
star
69

bamboo-log

a simple daemon and log tool, reload the print function.
Lua
1
star
70

jui

A modified version of dwz-ria, a web base front RIA js framework, clone from http://code.google.com/p/dwz/
JavaScript
1
star
71

bamboo-the-best-practice

The best practice for bamboo MVC web framework.
1
star
72

sapper_query

sappers urlencoded plugin to parse query string.
Rust
1
star
73

bamboo-plugin-navigator

navigator plugin for bamboo
Lua
1
star