Skip to content

Commit c9a6b01

Browse files
committed
Added browser demo for package:requests.
1 parent 9a7c402 commit c9a6b01

File tree

4 files changed

+402
-0
lines changed

4 files changed

+402
-0
lines changed

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ <h2>HTTP request from inside WASM in Dart - list of demos</h2>
1212
<li><a href="package-fetch-api/">Demo using package:fetch_api</a></li>
1313
<li><a href="package-fetch-client/">Demo using package:fetch_client</a></li>
1414
<li><a href="package-http/">Demo using package:http</a></li>
15+
<li><a href="package-requests/">Demo using package:requests</a></li>
1516
<li><a href="package-web/">Demo using package:web and fetch()</a></li>
1617
</ol>
1718

package-requests/index.html

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<title>HTTP request from WASM in Dart using package:requests</title>
7+
<script type="module">
8+
import { instantiate, invoke } from "./main.mjs";
9+
10+
const module = await WebAssembly.compileStreaming(fetch('main.wasm'));
11+
const instance = await instantiate(module);
12+
invoke(instance);
13+
</script>
14+
</head>
15+
16+
<body>
17+
<h2>HTTP Request from inside WASM in Dart using package:requests</h2>
18+
19+
<p>This example uses <a href="https://pub.dev/packages/requests">packages/requests</a>, but its new version 5.0.0 from
20+
<a href="https://github.com/jossef/requests/releases/tag/5.0.0">Github repo</a>.</p>
21+
22+
<p>See the output in browser developer console.</p>
23+
24+
<p>Actual code:</p>
25+
<pre>
26+
27+
import 'package:requests/requests.dart';
28+
29+
void main() async {
30+
final resp = await Requests.get('https://httpbin.org/anything');
31+
print('body: ${resp.content()}');
32+
}
33+
34+
</pre>
35+
<section>
36+
<h4>Info</h4>
37+
<ul>
38+
<li><a href="https://github.com/wasm-outbound-http-examples/dart/blob/main/browser-package-requests">Demo
39+
source code</a></li>
40+
<li>Versions used on the moment of build:<small>
41+
Dart SDK: <a href="https://github.com/dart-lang/sdk/releases/tag/3.5.2">v3.5.2</a>,
42+
package:requests: <a href="https://github.com/jossef/requests/releases/tag/5.0.0">v5.0.0</a>.
43+
</small></li>
44+
</ul>
45+
</section>
46+
<footer><small>Created for (wannabe-awesome) <a href="https://github.com/vasilev/HTTP-request-from-inside-WASM">list</a></small></footer>
47+
</body>
48+
</html>

0 commit comments

Comments
 (0)