describe http-client in readme

This commit is contained in:
Sebastian Hugentobler 2022-03-25 19:23:58 +01:00
parent 8bcd555d71
commit 385f3dff6f
5 changed files with 107 additions and 115 deletions

View File

@ -1,4 +1,4 @@
# vesys bank servers # vesys bank servers and clients
Implementations of a simple bank server for the 2022 vesys class at FHNW. Implementations of a simple bank server for the 2022 vesys class at FHNW.
Please note that the writer is in no way an experienced or even professional rust developer (hence the cloning everywhere) and Please note that the writer is in no way an experienced or even professional rust developer (hence the cloning everywhere) and
@ -12,10 +12,28 @@ Use an on-the-fly invented byte protocol. Consult the code for documentation.
An http implementation, using [actix-web](https://actix.rs/), wanted to try that for a while now. An http implementation, using [actix-web](https://actix.rs/), wanted to try that for a while now.
Again, consult the code for information on how the routes work. Again, consult the code for information on how the routes work.
## http-client
An experimental client for the http-server, built with rust, [yew](https://yew.rs/) and the power of web assembly.
First time I am trying this, there is probably even more wrong with it than with the server implementations.
# Usage # Usage
## Servers
Run it like you would with any [cargo workspace](https://doc.rust-lang.org/book/ch14-03-cargo-workspaces.html) project. Run it like you would with any [cargo workspace](https://doc.rust-lang.org/book/ch14-03-cargo-workspaces.html) project.
For example, starting the http-server variant, with debug logging and compiled in release mode: For example, starting the http-server variant, with debug logging and compiled in release mode:
``` ```
RUST_LOG=debug cargo run --release --bin http-server RUST_LOG=debug cargo run --release --bin http-server
``` ```
## http client
[Trunk](https://trunkrs.dev/) is used for wasm bundling.
Local development with auto-reload:
```
trunk serve
```
Build for release (the built artifacts can be found in `dist`):
```
trunk build --release
```

View File

@ -1,6 +1,35 @@
let wasm; let wasm;
const heap = new Array(32).fill(undefined);
heap.push(undefined, null, true, false);
function getObject(idx) { return heap[idx]; }
let heap_next = heap.length;
function dropObject(idx) {
if (idx < 36) return;
heap[idx] = heap_next;
heap_next = idx;
}
function takeObject(idx) {
const ret = getObject(idx);
dropObject(idx);
return ret;
}
function addHeapObject(obj) {
if (heap_next === heap.length) heap.push(heap.length + 1);
const idx = heap_next;
heap_next = heap[idx];
heap[idx] = obj;
return idx;
}
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }); let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
cachedTextDecoder.decode(); cachedTextDecoder.decode();
@ -17,23 +46,6 @@ function getStringFromWasm0(ptr, len) {
return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len)); return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
} }
const heap = new Array(32).fill(undefined);
heap.push(undefined, null, true, false);
let heap_next = heap.length;
function addHeapObject(obj) {
if (heap_next === heap.length) heap.push(heap.length + 1);
const idx = heap_next;
heap_next = heap[idx];
heap[idx] = obj;
return idx;
}
function getObject(idx) { return heap[idx]; }
let WASM_VECTOR_LEN = 0; let WASM_VECTOR_LEN = 0;
let cachedTextEncoder = new TextEncoder('utf-8'); let cachedTextEncoder = new TextEncoder('utf-8');
@ -109,18 +121,6 @@ function getFloat64Memory0() {
return cachegetFloat64Memory0; return cachegetFloat64Memory0;
} }
function dropObject(idx) {
if (idx < 36) return;
heap[idx] = heap_next;
heap_next = idx;
}
function takeObject(idx) {
const ret = getObject(idx);
dropObject(idx);
return ret;
}
function debugString(val) { function debugString(val) {
// primitive types // primitive types
const type = typeof val; const type = typeof val;
@ -208,7 +208,7 @@ function makeClosure(arg0, arg1, dtor, f) {
return real; return real;
} }
function __wbg_adapter_22(arg0, arg1, arg2) { function __wbg_adapter_22(arg0, arg1, arg2) {
wasm._dyn_core__ops__function__Fn__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h0b1695f7853f7e5d(arg0, arg1, addHeapObject(arg2)); wasm._dyn_core__ops__function__Fn__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h4d870f190d74430b(arg0, arg1, addHeapObject(arg2));
} }
function makeMutClosure(arg0, arg1, dtor, f) { function makeMutClosure(arg0, arg1, dtor, f) {
@ -236,7 +236,7 @@ function makeMutClosure(arg0, arg1, dtor, f) {
return real; return real;
} }
function __wbg_adapter_25(arg0, arg1, arg2) { function __wbg_adapter_25(arg0, arg1, arg2) {
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h0235f8df8778306b(arg0, arg1, addHeapObject(arg2)); wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hd4fb9e7e84e48093(arg0, arg1, addHeapObject(arg2));
} }
let cachegetUint32Memory0 = null; let cachegetUint32Memory0 = null;
@ -298,10 +298,17 @@ async function load(module, imports) {
async function init(input) { async function init(input) {
if (typeof input === 'undefined') { if (typeof input === 'undefined') {
input = new URL('index-57ce73b23c43b0f5_bg.wasm', import.meta.url); input = new URL('index-5172744d856158ca_bg.wasm', import.meta.url);
} }
const imports = {}; const imports = {};
imports.wbg = {}; imports.wbg = {};
imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
takeObject(arg0);
};
imports.wbg.__wbindgen_object_clone_ref = function(arg0) {
var ret = getObject(arg0);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_string_new = function(arg0, arg1) { imports.wbg.__wbindgen_string_new = function(arg0, arg1) {
var ret = getStringFromWasm0(arg0, arg1); var ret = getStringFromWasm0(arg0, arg1);
return addHeapObject(ret); return addHeapObject(ret);
@ -314,9 +321,14 @@ async function init(input) {
getInt32Memory0()[arg0 / 4 + 1] = len0; getInt32Memory0()[arg0 / 4 + 1] = len0;
getInt32Memory0()[arg0 / 4 + 0] = ptr0; getInt32Memory0()[arg0 / 4 + 0] = ptr0;
}; };
imports.wbg.__wbindgen_object_clone_ref = function(arg0) { imports.wbg.__wbindgen_cb_drop = function(arg0) {
var ret = getObject(arg0); const obj = takeObject(arg0).original;
return addHeapObject(ret); if (obj.cnt-- == 1) {
obj.a = 0;
return true;
}
var ret = false;
return ret;
}; };
imports.wbg.__wbindgen_number_new = function(arg0) { imports.wbg.__wbindgen_number_new = function(arg0) {
var ret = arg0; var ret = arg0;
@ -328,13 +340,6 @@ async function init(input) {
getFloat64Memory0()[arg0 / 8 + 1] = isLikeNone(ret) ? 0 : ret; getFloat64Memory0()[arg0 / 8 + 1] = isLikeNone(ret) ? 0 : ret;
getInt32Memory0()[arg0 / 4 + 0] = !isLikeNone(ret); getInt32Memory0()[arg0 / 4 + 0] = !isLikeNone(ret);
}; };
imports.wbg.__wbg_error_09919627ac0992f5 = function(arg0, arg1) {
try {
console.error(getStringFromWasm0(arg0, arg1));
} finally {
wasm.__wbindgen_free(arg0, arg1);
}
};
imports.wbg.__wbg_new_693216e109162396 = function() { imports.wbg.__wbg_new_693216e109162396 = function() {
var ret = new Error(); var ret = new Error();
return addHeapObject(ret); return addHeapObject(ret);
@ -346,8 +351,12 @@ async function init(input) {
getInt32Memory0()[arg0 / 4 + 1] = len0; getInt32Memory0()[arg0 / 4 + 1] = len0;
getInt32Memory0()[arg0 / 4 + 0] = ptr0; getInt32Memory0()[arg0 / 4 + 0] = ptr0;
}; };
imports.wbg.__wbindgen_object_drop_ref = function(arg0) { imports.wbg.__wbg_error_09919627ac0992f5 = function(arg0, arg1) {
takeObject(arg0); try {
console.error(getStringFromWasm0(arg0, arg1));
} finally {
wasm.__wbindgen_free(arg0, arg1);
}
}; };
imports.wbg.__wbg_warn_2aa0e7178e1d35f6 = function(arg0, arg1) { imports.wbg.__wbg_warn_2aa0e7178e1d35f6 = function(arg0, arg1) {
var v0 = getArrayJsValueFromWasm0(arg0, arg1).slice(); var v0 = getArrayJsValueFromWasm0(arg0, arg1).slice();
@ -382,14 +391,17 @@ async function init(input) {
var ret = getObject(arg0).createTextNode(getStringFromWasm0(arg1, arg2)); var ret = getObject(arg0).createTextNode(getStringFromWasm0(arg1, arg2));
return addHeapObject(ret); return addHeapObject(ret);
}; };
imports.wbg.__wbg_value_d3a30bc2c7caf357 = function(arg0, arg1) { imports.wbg.__wbg_setchecked_f6ead3490df88a7f = function(arg0, arg1) {
getObject(arg0).checked = arg1 !== 0;
};
imports.wbg.__wbg_value_fc1c354d1a0e9714 = function(arg0, arg1) {
var ret = getObject(arg1).value; var ret = getObject(arg1).value;
var ptr0 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); var ptr0 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
var len0 = WASM_VECTOR_LEN; var len0 = WASM_VECTOR_LEN;
getInt32Memory0()[arg0 / 4 + 1] = len0; getInt32Memory0()[arg0 / 4 + 1] = len0;
getInt32Memory0()[arg0 / 4 + 0] = ptr0; getInt32Memory0()[arg0 / 4 + 0] = ptr0;
}; };
imports.wbg.__wbg_setvalue_6a34bab301f38bf2 = function(arg0, arg1, arg2) { imports.wbg.__wbg_setvalue_ce4a23f487065c07 = function(arg0, arg1, arg2) {
getObject(arg0).value = getStringFromWasm0(arg1, arg2); getObject(arg0).value = getStringFromWasm0(arg1, arg2);
}; };
imports.wbg.__wbg_target_e560052e31e4567c = function(arg0) { imports.wbg.__wbg_target_e560052e31e4567c = function(arg0) {
@ -408,19 +420,6 @@ async function init(input) {
var ret = new Request(getStringFromWasm0(arg0, arg1), getObject(arg2)); var ret = new Request(getStringFromWasm0(arg0, arg1), getObject(arg2));
return addHeapObject(ret); return addHeapObject(ret);
}, arguments) }; }, arguments) };
imports.wbg.__wbg_setchecked_f6ead3490df88a7f = function(arg0, arg1) {
getObject(arg0).checked = arg1 !== 0;
};
imports.wbg.__wbg_value_fc1c354d1a0e9714 = function(arg0, arg1) {
var ret = getObject(arg1).value;
var ptr0 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
var len0 = WASM_VECTOR_LEN;
getInt32Memory0()[arg0 / 4 + 1] = len0;
getInt32Memory0()[arg0 / 4 + 0] = ptr0;
};
imports.wbg.__wbg_setvalue_ce4a23f487065c07 = function(arg0, arg1, arg2) {
getObject(arg0).value = getStringFromWasm0(arg1, arg2);
};
imports.wbg.__wbg_addEventListener_55682f77717d7665 = function() { return handleError(function (arg0, arg1, arg2, arg3, arg4) { imports.wbg.__wbg_addEventListener_55682f77717d7665 = function() { return handleError(function (arg0, arg1, arg2, arg3, arg4) {
getObject(arg0).addEventListener(getStringFromWasm0(arg1, arg2), getObject(arg3), getObject(arg4)); getObject(arg0).addEventListener(getStringFromWasm0(arg1, arg2), getObject(arg3), getObject(arg4));
}, arguments) }; }, arguments) };
@ -447,6 +446,13 @@ async function init(input) {
var ret = getObject(arg0).removeChild(getObject(arg1)); var ret = getObject(arg0).removeChild(getObject(arg1));
return addHeapObject(ret); return addHeapObject(ret);
}, arguments) }; }, arguments) };
imports.wbg.__wbg_value_d4cea9e999ffb147 = function(arg0, arg1) {
var ret = getObject(arg1).value;
var ptr0 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
var len0 = WASM_VECTOR_LEN;
getInt32Memory0()[arg0 / 4 + 1] = len0;
getInt32Memory0()[arg0 / 4 + 0] = ptr0;
};
imports.wbg.__wbg_instanceof_Element_c9423704dd5d9b1d = function(arg0) { imports.wbg.__wbg_instanceof_Element_c9423704dd5d9b1d = function(arg0) {
var ret = getObject(arg0) instanceof Element; var ret = getObject(arg0) instanceof Element;
return ret; return ret;
@ -467,13 +473,16 @@ async function init(input) {
imports.wbg.__wbg_set_f9448486a94c9aef = function() { return handleError(function (arg0, arg1, arg2, arg3, arg4) { imports.wbg.__wbg_set_f9448486a94c9aef = function() { return handleError(function (arg0, arg1, arg2, arg3, arg4) {
getObject(arg0).set(getStringFromWasm0(arg1, arg2), getStringFromWasm0(arg3, arg4)); getObject(arg0).set(getStringFromWasm0(arg1, arg2), getStringFromWasm0(arg3, arg4));
}, arguments) }; }, arguments) };
imports.wbg.__wbg_value_d4cea9e999ffb147 = function(arg0, arg1) { imports.wbg.__wbg_value_d3a30bc2c7caf357 = function(arg0, arg1) {
var ret = getObject(arg1).value; var ret = getObject(arg1).value;
var ptr0 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); var ptr0 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
var len0 = WASM_VECTOR_LEN; var len0 = WASM_VECTOR_LEN;
getInt32Memory0()[arg0 / 4 + 1] = len0; getInt32Memory0()[arg0 / 4 + 1] = len0;
getInt32Memory0()[arg0 / 4 + 0] = ptr0; getInt32Memory0()[arg0 / 4 + 0] = ptr0;
}; };
imports.wbg.__wbg_setvalue_6a34bab301f38bf2 = function(arg0, arg1, arg2) {
getObject(arg0).value = getStringFromWasm0(arg1, arg2);
};
imports.wbg.__wbg_instanceof_Response_ea36d565358a42f7 = function(arg0) { imports.wbg.__wbg_instanceof_Response_ea36d565358a42f7 = function(arg0) {
var ret = getObject(arg0) instanceof Response; var ret = getObject(arg0) instanceof Response;
return ret; return ret;
@ -482,23 +491,22 @@ async function init(input) {
var ret = getObject(arg0).text(); var ret = getObject(arg0).text();
return addHeapObject(ret); return addHeapObject(ret);
}, arguments) }; }, arguments) };
imports.wbg.__wbindgen_cb_drop = function(arg0) {
const obj = takeObject(arg0).original;
if (obj.cnt-- == 1) {
obj.a = 0;
return true;
}
var ret = false;
return ret;
};
imports.wbg.__wbg_newnoargs_f579424187aa1717 = function(arg0, arg1) { imports.wbg.__wbg_newnoargs_f579424187aa1717 = function(arg0, arg1) {
var ret = new Function(getStringFromWasm0(arg0, arg1)); var ret = new Function(getStringFromWasm0(arg0, arg1));
return addHeapObject(ret); return addHeapObject(ret);
}; };
imports.wbg.__wbg_get_8bbb82393651dd9c = function() { return handleError(function (arg0, arg1) {
var ret = Reflect.get(getObject(arg0), getObject(arg1));
return addHeapObject(ret);
}, arguments) };
imports.wbg.__wbg_call_89558c3e96703ca1 = function() { return handleError(function (arg0, arg1) { imports.wbg.__wbg_call_89558c3e96703ca1 = function() { return handleError(function (arg0, arg1) {
var ret = getObject(arg0).call(getObject(arg1)); var ret = getObject(arg0).call(getObject(arg1));
return addHeapObject(ret); return addHeapObject(ret);
}, arguments) }; }, arguments) };
imports.wbg.__wbg_new_d3138911a89329b0 = function() {
var ret = new Object();
return addHeapObject(ret);
};
imports.wbg.__wbg_valueOf_39e0d6bc7e4232b9 = function(arg0) { imports.wbg.__wbg_valueOf_39e0d6bc7e4232b9 = function(arg0) {
var ret = getObject(arg0).valueOf(); var ret = getObject(arg0).valueOf();
return ret; return ret;
@ -507,10 +515,6 @@ async function init(input) {
var ret = Object.is(getObject(arg0), getObject(arg1)); var ret = Object.is(getObject(arg0), getObject(arg1));
return ret; return ret;
}; };
imports.wbg.__wbg_new_d3138911a89329b0 = function() {
var ret = new Object();
return addHeapObject(ret);
};
imports.wbg.__wbg_resolve_4f8f547f26b30b27 = function(arg0) { imports.wbg.__wbg_resolve_4f8f547f26b30b27 = function(arg0) {
var ret = Promise.resolve(getObject(arg0)); var ret = Promise.resolve(getObject(arg0));
return addHeapObject(ret); return addHeapObject(ret);
@ -523,10 +527,6 @@ async function init(input) {
var ret = getObject(arg0).then(getObject(arg1), getObject(arg2)); var ret = getObject(arg0).then(getObject(arg1), getObject(arg2));
return addHeapObject(ret); return addHeapObject(ret);
}; };
imports.wbg.__wbg_globalThis_d61b1f48a57191ae = function() { return handleError(function () {
var ret = globalThis.globalThis;
return addHeapObject(ret);
}, arguments) };
imports.wbg.__wbg_self_e23d74ae45fb17d1 = function() { return handleError(function () { imports.wbg.__wbg_self_e23d74ae45fb17d1 = function() { return handleError(function () {
var ret = self.self; var ret = self.self;
return addHeapObject(ret); return addHeapObject(ret);
@ -535,6 +535,10 @@ async function init(input) {
var ret = window.window; var ret = window.window;
return addHeapObject(ret); return addHeapObject(ret);
}, arguments) }; }, arguments) };
imports.wbg.__wbg_globalThis_d61b1f48a57191ae = function() { return handleError(function () {
var ret = globalThis.globalThis;
return addHeapObject(ret);
}, arguments) };
imports.wbg.__wbg_global_e7669da72fd7f239 = function() { return handleError(function () { imports.wbg.__wbg_global_e7669da72fd7f239 = function() { return handleError(function () {
var ret = global.global; var ret = global.global;
return addHeapObject(ret); return addHeapObject(ret);
@ -543,10 +547,6 @@ async function init(input) {
var ret = getObject(arg0) === undefined; var ret = getObject(arg0) === undefined;
return ret; return ret;
}; };
imports.wbg.__wbg_get_8bbb82393651dd9c = function() { return handleError(function (arg0, arg1) {
var ret = Reflect.get(getObject(arg0), getObject(arg1));
return addHeapObject(ret);
}, arguments) };
imports.wbg.__wbg_set_c42875065132a932 = function() { return handleError(function (arg0, arg1, arg2) { imports.wbg.__wbg_set_c42875065132a932 = function() { return handleError(function (arg0, arg1, arg2) {
var ret = Reflect.set(getObject(arg0), getObject(arg1), getObject(arg2)); var ret = Reflect.set(getObject(arg0), getObject(arg1), getObject(arg2));
return ret; return ret;
@ -561,12 +561,12 @@ async function init(input) {
imports.wbg.__wbindgen_throw = function(arg0, arg1) { imports.wbg.__wbindgen_throw = function(arg0, arg1) {
throw new Error(getStringFromWasm0(arg0, arg1)); throw new Error(getStringFromWasm0(arg0, arg1));
}; };
imports.wbg.__wbindgen_closure_wrapper4145 = function(arg0, arg1, arg2) { imports.wbg.__wbindgen_closure_wrapper445 = function(arg0, arg1, arg2) {
var ret = makeClosure(arg0, arg1, 178, __wbg_adapter_22); var ret = makeClosure(arg0, arg1, 148, __wbg_adapter_22);
return addHeapObject(ret); return addHeapObject(ret);
}; };
imports.wbg.__wbindgen_closure_wrapper7730 = function(arg0, arg1, arg2) { imports.wbg.__wbindgen_closure_wrapper1172 = function(arg0, arg1, arg2) {
var ret = makeMutClosure(arg0, arg1, 194, __wbg_adapter_25); var ret = makeMutClosure(arg0, arg1, 192, __wbg_adapter_25);
return addHeapObject(ret); return addHeapObject(ret);
}; };

Binary file not shown.

Binary file not shown.

View File

@ -3,32 +3,6 @@
<title>Vesys Bank</title> <title>Vesys Bank</title>
<link rel="stylesheet" href="/styles-3143ec7e42adb2c6.css"> <link rel="stylesheet" href="/styles-3143ec7e42adb2c6.css">
<link rel="preload" href="/index-57ce73b23c43b0f5_bg.wasm" as="fetch" type="application/wasm" crossorigin=""> <link rel="preload" href="/index-5172744d856158ca_bg.wasm" as="fetch" type="application/wasm" crossorigin="">
<link rel="modulepreload" href="/index-57ce73b23c43b0f5.js"></head> <link rel="modulepreload" href="/index-5172744d856158ca.js"></head>
<body><script type="module">import init from '/index-57ce73b23c43b0f5.js';init('/index-57ce73b23c43b0f5_bg.wasm');</script><script>(function () { <body><script type="module">import init from '/index-5172744d856158ca.js';init('/index-5172744d856158ca_bg.wasm');</script></body></html>
var url = 'ws://' + window.location.host + '/_trunk/ws';
var poll_interval = 5000;
var reload_upon_connect = () => {
window.setTimeout(
() => {
// when we successfully reconnect, we'll force a
// reload (since we presumably lost connection to
// trunk due to it being killed, so it will have
// rebuilt on restart)
var ws = new WebSocket(url);
ws.onopen = () => window.location.reload();
ws.onclose = reload_upon_connect;
},
poll_interval);
};
var ws = new WebSocket(url);
ws.onmessage = (ev) => {
const msg = JSON.parse(ev.data);
if (msg.reload) {
window.location.reload();
}
};
ws.onclose = reload_upon_connect;
})()
</script></body></html>