Browse Source

xitca-web-wasm: Add an implementation of the JSON serialization test (#8133)

Anton Kirilov 2 years ago
parent
commit
a50d43b10e

+ 1 - 1
frameworks/Rust/xitca-web/Cargo.toml

@@ -26,7 +26,7 @@ required-features = ["pg", "serde", "template"]
 [[bin]]
 name = "xitca-web-wasm"
 path = "./src/main_wasm.rs"
-required-features = ["web"]
+required-features = ["serde", "web"]
 
 [features]
 # pg optional

+ 1 - 0
frameworks/Rust/xitca-web/benchmark_config.json

@@ -91,6 +91,7 @@
         "versus": ""
       },
       "wasm": {
+        "json_url": "/json",
         "plaintext_url": "/plaintext",
         "port": 8080,
         "approach": "Realistic",

+ 1 - 0
frameworks/Rust/xitca-web/config.toml

@@ -49,6 +49,7 @@ webserver = "xitca-server"
 versus = ""
 
 [wasm]
+urls.json = "/json"
 urls.plaintext = "/plaintext"
 approach = "Realistic"
 classification = "Micro"

+ 14 - 2
frameworks/Rust/xitca-web/src/main_wasm.rs

@@ -1,10 +1,16 @@
+mod ser;
 mod util;
 
 use std::{env, io, net::TcpListener, os::wasi::io::FromRawFd};
 
 use xitca_web::{
-    dev::service::Service, handler::handler_service, http::header::SERVER, request::WebRequest,
-    response::WebResponse, route::get, App, HttpServer,
+    dev::service::Service,
+    handler::{handler_service, json::Json},
+    http::header::SERVER,
+    request::WebRequest,
+    response::WebResponse,
+    route::get,
+    App, HttpServer,
 };
 
 use self::util::SERVER_HEADER_VALUE;
@@ -19,6 +25,12 @@ fn main() -> io::Result<()> {
 
     HttpServer::new(|| {
         App::new()
+            .at(
+                "/json",
+                get(handler_service(|| async {
+                    Json::<ser::Message>(ser::Message::new())
+                })),
+            )
             .at(
                 "/plaintext",
                 get(handler_service(|| async { "Hello, World!" })),

+ 1 - 1
frameworks/Rust/xitca-web/xitca-web-wasm.dockerfile

@@ -7,7 +7,7 @@ COPY / ./
 RUN curl -LSs "https://github.com/bytecodealliance/wasmtime/releases/download/v${WASMTIME_VERSION}/wasmtime-v${WASMTIME_VERSION}-$(uname -m)-linux.tar.xz" | \
       tar --strip-components=1 -Jx && \
     rustup target add wasm32-wasi && \
-    cargo build --bin xitca-web-wasm --features web --release --target wasm32-wasi
+    cargo build --bin xitca-web-wasm --features serde,web --release --target wasm32-wasi
 
 FROM ubuntu:22.04