HTTP Request from inside WASM using FreePascal and its ShortString

This example uses Free Pascal and bjorn3/browser_wasi_shim.

See the output in browser developer console.

ShortString approach

Actual code:


function httpGet(url: ShortString; Var str_out:
    ShortString): ShortString; external 'wasi_snapshot_preview1';

var out_str : ShortString;

begin
        out_str:= DupeString( ' ' , 255 );

        httpGet('https://httpbin.org/get', out_str);

        writeln(out_str);
end.

Info

Warning This example employs XMLHTTPRequest in synchronous form. Consider making such calls only from inside of Web Workers to avoid UI freezes.