Browse Source

Added Saphir Rust http framework (#4342)

* Added rust framework saphir

* Added rust/saphir to testdir inside .travis.yml

* Added desciption + relevant links to the readme.md
Richer Archambault 6 years ago
parent
commit
3f5ae4d173

+ 1 - 1
.travis.yml

@@ -99,7 +99,7 @@ env:
      - 'TESTDIR="PHP/amp PHP/hamlet PHP/hhvm PHP/peachpie PHP/swoole PHP/workerman PHP/phalcon"'
      - "TESTLANG=Python"
      - "TESTLANG=Ruby"
-     - 'TESTDIR="Rust/actix Rust/gotham Rust/hyper Rust/iron"'
+     - 'TESTDIR="Rust/actix Rust/gotham Rust/hyper Rust/iron Rust/saphir"'
      - 'TESTDIR="Rust/may-minihttp Rust/nickel Rust/rocket"'
      - 'TESTDIR="Rust/rouille Rust/thruster Rust/tokio-minihttp"'
      - "TESTLANG=Scala"

+ 11 - 0
frameworks/Rust/saphir/Cargo.toml

@@ -0,0 +1,11 @@
+[package]
+name = "saphir-techempower"
+version = "0.1.0"
+authors = ["richer <[email protected]>"]
+edition = "2018"
+
+[dependencies]
+saphir = "0.8.1"
+serde = "1.0"
+serde_derive = "1.0"
+serde_json = "1.0"

+ 50 - 0
frameworks/Rust/saphir/README.md

@@ -0,0 +1,50 @@
+# Saphir Benchmarking Test
+
+Saphir is a fast and lightweight web framework that aims to give lowlevel control over your web stack without the pain of re-doing everything from scratch.
+
+* [Repo](https://github.com/richerarc/saphir)
+* [API Documentation](https://docs.rs/saphir/)
+* Cargo package: [saphir](https://crates.io/crates/saphir)
+
+### Test Type Implementation Source Code
+
+* [JSON](src/main.rs)
+* [PLAINTEXT](src/main.rs)
+* [DB](src/main.rs)
+* [QUERY](src/main.rs)
+* [CACHED QUERY](src/main.rs)
+* [UPDATE](src/main.rs)
+* [FORTUNES](src/main.rs)
+
+## Important Libraries
+The tests were run with:
+* [serde](https://github.com/serde-rs/serde)
+
+## Test URLs
+### JSON
+
+http://localhost:8080/json
+
+### PLAINTEXT
+
+http://localhost:8080/plaintext
+
+### ~~DB~~
+
+~~http://localhost:8080/db~~
+
+### ~~QUERY~~
+
+~~http://localhost:8080/query?queries=~~
+
+### ~~CACHED QUERY~~
+
+~~http://localhost:8080/cached_query?queries=~~
+
+### ~~UPDATE~~
+
+~~http://localhost:8080/update?queries=~~
+
+### ~~FORTUNES~~
+
+~~http://localhost:8080/fortunes~~

+ 26 - 0
frameworks/Rust/saphir/benchmark_config.json

@@ -0,0 +1,26 @@
+{
+  "framework": "saphir",
+  "tests": [
+    {
+      "default": {
+        "json_url": "/json",
+        "plaintext_url": "/plaintext",
+        "port": 8080,
+        "approach": "Realistic",
+        "classification": "Micro",
+        "database": "None",
+        "framework": "Saphir",
+        "language": "Rust",
+        "flavor": "None",
+        "orm": "None",
+        "platform": "None",
+        "webserver": "None",
+        "os": "Linux",
+        "database_os": "Linux",
+        "display_name": "Saphir",
+        "notes": "",
+        "versus": "hyper"
+      }
+    }
+  ]
+}

+ 12 - 0
frameworks/Rust/saphir/saphir.dockerfile

@@ -0,0 +1,12 @@
+FROM rust:1.31.1
+
+WORKDIR saphir
+
+ADD . .
+
+RUN cargo clean
+RUN cargo build --release
+
+EXPOSE 8080
+
+ENTRYPOINT [ "./target/release/saphir-techempower" ]

+ 52 - 0
frameworks/Rust/saphir/src/main.rs

@@ -0,0 +1,52 @@
+extern crate saphir;
+#[macro_use]
+extern crate serde_derive;
+extern crate serde_json;
+extern crate serde;
+
+use saphir::*;
+
+static HELLO_WORLD: &'static [u8] = b"Hello, world!";
+
+#[derive(Serialize)]
+struct ResponseJsonBody<'t0> {
+    message: &'t0 str,
+}
+
+fn main() {
+    let server_builder = Server::builder();
+
+    let server = server_builder
+        .configure_router(|router| {
+            let plaintext = BasicController::new("^/plaintext", ());
+            plaintext.add(Method::GET, reg!("^/$"), |_, _, res| { 
+                res.header(header::CONTENT_TYPE, "text/plain")
+                    .header(header::SERVER, "Saphir")
+                    .status(StatusCode::OK)
+                    .body(HELLO_WORLD); 
+            });
+
+            let json = BasicController::new("^/json", ());
+            json.add(Method::GET, reg!("^/$"), |_, _, res| { 
+                let body = ResponseJsonBody{ message: "hello, world!" };
+                let json_str = ::serde_json::to_string(&body).expect("this body serialization should never fail");
+                res.header(header::CONTENT_TYPE, "application/json")
+                    .header(header::SERVER, "Saphir")
+                    .status(StatusCode::OK)
+                    .body(json_str);
+            });
+
+            router.add(plaintext)
+            .add(json)
+        })
+        .configure_listener(|listener_config| {
+            listener_config.set_uri("http://0.0.0.0:8080")
+                .set_request_timeout_ms(5000) // 10 sec
+                .set_panic_handler(|panic| {
+                    println!("HA HA! : {:?}", panic);
+                })
+        })
+        .build();
+
+    server.run().unwrap();
+}