summaryrefslogtreecommitdiffstats
path: root/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/samples/request_sender.ts
blob: 5648985e769b13fdce8f0c0e0cb6296d8a4f0e50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
 * Copyright (C) 2019 Intel Corporation.  All rights reserved.
 * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 */

// The entry file of your WebAssembly module.
import * as console from "../wamr_app_lib/console"
import * as timer from "../wamr_app_lib/timer"
import * as request from "../wamr_app_lib/request"

export function on_init() : void {
    var payload = String.UTF8.encode("test message");
    request.post("/test", payload, payload.byteLength, "", (resp) => {
        if (resp != null) {
            console.log("Post Success");

            if (resp.payload != null) {
                console.log("    response payload:")
                console.log("    " + String.UTF8.decode(resp.payload!) + "\n");
            }
        }
        else
            console.log("Post Timeout");
    });
}

export function on_destroy() : void {

}


/* Function below are requred by wamr runtime, don't remove or modify them */
export function _on_timer_callback(on_timer_id: i32): void {
    timer.on_timer_callback(on_timer_id);
}

export function _on_request(buffer_offset: i32, size: i32): void {
    request.on_request(buffer_offset, size);
}

export function _on_response(buffer_offset : i32, size: i32): void {
    request.on_response(buffer_offset, size);
}