Skip to content

Commit 9a7c402

Browse files
committed
Added browser demo for package:dio.
1 parent 1e9ed44 commit 9a7c402

File tree

6 files changed

+436
-2
lines changed

6 files changed

+436
-2
lines changed

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<h2>HTTP request from inside WASM in Dart - list of demos</h2>
99

1010
<ol>
11+
<li><a href="package-dio/">Demo using package:dio</a></li>
1112
<li><a href="package-fetch-api/">Demo using package:fetch_api</a></li>
1213
<li><a href="package-fetch-client/">Demo using package:fetch_client</a></li>
1314
<li><a href="package-http/">Demo using package:http</a></li>

package-dio/index.html

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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:dio</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:dio</h2>
18+
19+
<p>This example uses <a href="https://pub.dev/packages/dio">packages/dio</a>.</p>
20+
21+
<p>See the output in browser developer console.</p>
22+
23+
<p>Actual code:</p>
24+
<pre>
25+
26+
import 'package:dio/dio.dart';
27+
28+
final dio = Dio();
29+
Response response = await dio.get('https://httpbin.org/anything');
30+
print(response);
31+
32+
</pre>
33+
<section>
34+
<h4>Info</h4>
35+
<ul>
36+
<li><a href="https://github.com/wasm-outbound-http-examples/dart/tree/main/browser-package-dio">Demo
37+
source code</a></li>
38+
<li>Versions used on the moment of build:<small>
39+
Dart SDK: <a href="https://github.com/dart-lang/sdk/releases/tag/3.5.2">v3.5.2</a>,
40+
package:dio: <a href="https://pub.dev/packages/dio/versions/5.7.0">v5.7.0</a>.
41+
</small></li>
42+
</ul>
43+
</section>
44+
<footer><small>Created for (wannabe-awesome) <a href="https://github.com/vasilev/HTTP-request-from-inside-WASM">list</a></small></footer>
45+
</body>
46+
</html>

0 commit comments

Comments
 (0)