├── ARCHIVE.md ├── LICENSE └── README.md /ARCHIVE.md: -------------------------------------------------------------------------------- 1 | ARCHIVE of "Make HTTP request from inside WebAssembly" list 2 | =========================================================== 3 | 4 | > [!CAUTION] 5 | > Approaches listed on this page are deprecated or/and do not longer work. 6 | > They are collected here for historical purposes. 7 | 8 | Each item has hyperlink to up-to-date alternative in the [main list](README.md). 9 | 10 | ### Contents 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 25 | 26 | 27 | 28 | 33 | 38 | 39 | 40 | 41 | 46 | 51 | 52 | 53 | 54 | 55 | 60 | 61 | 62 | 63 | 68 | 69 | 70 | 71 | 72 | 77 | 78 | 79 | 80 | 81 | 82 | 87 | 88 | 89 | 90 | 91 | 96 | 97 |
LanguageBrowsers and JS runtimesStandalone / server-side / WASI runtimes
AssemblyScript 21 | 22 | [wasi-experimental-http, wasi-http-ts](#assemblyscript-wasi) 23 | 24 |
C# / .Net 29 | 30 | [Uno Platform](#csharp) 31 | 32 | 34 | 35 | [wasi-experimental-http](#csharp-wasi) 36 | 37 |
C / C++ 42 | 43 | 44 | 45 | 47 | 48 | [wasi-experimental-http](#cpp-wasi) 49 | 50 |
Golang / TinyGo 56 | 57 | [wasi-experimental-http](#golang-wasi) 58 | 59 |
PHP 64 | 65 | [PIB aka php-wasm](#php) 66 | 67 |
Python 73 | 74 | [requests-wasm-polyfill](#python) 75 | 76 |
Rust 83 | 84 | [wasi-experimental-http](#rust-wasi) 85 | 86 |
Zig 92 | 93 | [wasi-experimental-http](#zig-wasi) 94 | 95 |
98 | 99 | Browser WASM runtimes and standalone JS runtimes like Node.js and Deno (and other V8-based), also Bun 100 | ----------------------------------------------------------------------------------------------------- 101 | 102 | 103 | ### C# 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 123 | 143 | 148 | 153 | 158 | 159 | 165 | 166 |
Product / ImplementationTLDR: UsageTLDR: Example codeDocOnline demoWASM RuntimeInternals: method to do real request
112 | 113 | [Uno Platform](https://platform.uno/) 114 | 115 | > [!CAUTION] 116 | > `Uno.UI.Wasm. WasmHttpHandler` deprecated since .NET 6 117 | 118 | 119 | > [!TIP] 120 | > [Use](README.md#uno-platform) `System.Net. Http.HttpClient` instead. 121 | 122 | 124 | 125 | ```csharp 126 | // Uno Platform's own way 127 | // Deprecated since .NET 6, 128 | // use 'System.Net.Http.HttpClient' and 'HttpHandler' instead 129 | // See https://github.com/unoplatform/uno/issues/9665 130 | using System.Net.Http; 131 | 132 | using (var handler = new Uno.UI.Wasm.WasmHttpHandler()) 133 | using (var client = new HttpClient(handler)) 134 | { 135 | var request = new HttpRequestMessage(HttpMethod.Get, 136 | new Uri("https://httpbin.org/anything")); 137 | var response = await client.SendAsync(request); 138 | var content = await response.Content.ReadAsStringAsync(); 139 | } 140 | ``` 141 | 142 | 144 | 145 | [Test](https://github.com/unoplatform/uno/blob/4.7.37/src/SamplesApp/SamplesApp.Shared/Samples/UnitTests/HttpUnitTests.xaml.cs#L33) 146 | 147 | 149 | 150 | [Tutorial](https://platform.uno/docs/articles/howto-consume-webservices.html) 151 | 152 | 154 | 155 | [Playground](https://playground.platform.uno/) 156 | 157 | Browser 160 | 161 | [JS Interop](https://github.com/unoplatform/uno/blob/4.7.37/src/Uno.UI.Runtime.WebAssembly/WasmHttpHandler.cs#L62) invokes the TS 162 | [wrapper](https://github.com/unoplatform/uno/blob/4.7.37/src/Uno.UI/ts/HttpClient.ts#L27) for `fetch` 163 | 164 |
167 | 168 | ### PHP 169 | 170 | 171 | 172 | 173 | 174 | 175 | 187 | 207 | 212 | 218 | 219 | 224 | 225 |
Product / ImplementationTLDR: UsageTLDR: Example codeDocOnline demoWASM RuntimeInternals: method to do real request
176 | 177 | [PIB: PHP in Browser aka php-wasm](https://github.com/seanmorris/php-wasm/) 178 | 179 | > [!CAUTION] 180 | > This code does not work in php-wasm v0.0.8. 181 | 182 | 183 | > [!TIP] 184 | > Use [up-to-date method](README.md#php-wasm) instead. 185 | 186 | 188 | 189 | ```php 190 | $js=<< 202 | 203 | 204 | [Example](https://github.com/WordPress/wordpress-playground/blob/bb148069e37d8b7f3314a3e675abb316f7749e4e/src/wordpress-playground/mu-plugins/includes/requests_transport_fetch.php#L68) 205 | 206 | 208 | 209 | [Doc](https://github.com/seanmorris/vrzno#usage) 210 | 211 | 213 | 214 | * [Demo](https://seanmorris.github.io/php-wasm/?autorun=0&persist=0&single-expression=0&code=%253C%253Fphp%250A%2524js%253D%253C%253C%253CJSCODE%250Avar%2520xhr%253Dnew%2520XMLHttpRequest%28%29%253B%250Axhr.open%28%27GET%27%252C%2520%27https%253A%252F%252Fhttpbin.org%252Fanything%27%252C%25200%29%253B%250Axhr.send%28%29%253B%250A%250Axhr.responseText%253B%250AJSCODE%253B%250A%250Avar_dump%28vrzno_eval%28%2524js%29%29%253B%250A) 215 | * [Playground](https://seanmorris.github.io/php-wasm/) 216 | 217 | Browser, Node.js, and maybe Deno 220 | 221 | Manual JS `XMLHttpRequest` interop using [`vrzno`](https://github.com/seanmorris/vrzno/blob/228514316299f8d1dbc8abcff51523ed37929f1f/vrzno.c#L36) PHP extension. 222 | 223 |
226 | 227 | 228 | ### Python 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 250 | 261 | 266 | 267 | 273 | 278 | 284 | 285 |
Product / ImplementationTLDR: UsageTLDR: Example codeDocOnline demoWASM RuntimeInternals: method to do real request
237 | 238 | [requests-wasm-polyfill](https://github.com/emscripten-forge/requests-wasm-polyfill) 239 | 240 | For [pyjs](https://github.com/emscripten-forge/pyjs) 241 | 242 | > [!CAUTION] 243 | > Repo was [archived](https://github.com/emscripten-forge/requests-wasm-polyfill/issues/7) and package was [dropped from recipes](https://github.com/emscripten-forge/recipes/pull/796) on Feb 6, 2024. 244 | 245 | 246 | > [!TIP] 247 | > [Use](https://github.com/emscripten-forge/requests-wasm-polyfill/blob/568560020f74704c183fe49f8e527942d19e276c/README.md?plain=1#L8) the official `requests` instead. 248 | 249 | 251 | 252 | ```python 253 | import requests 254 | 255 | r = requests.get('https://httpbin.org/anything') 256 | result = r.text 257 | print(result) 258 | ``` 259 | 260 | 262 | 263 | [Example](https://github.com/wasm-outbound-http-examples/pyjs/blob/596d23d2dcd930ec7025eb734feaaffa478c13f5/requests-wasm-polyfill/script.js#L26) 264 | 265 | 268 | 269 | * [Demo](https://wasm-outbound-http-examples.github.io/pyjs/requests-wasm-polyfill/) 270 | * [Dev Container](https://codespaces.new/wasm-outbound-http-examples/pyjs) 271 | 272 | 274 | 275 | Browser 276 | 277 | 279 | 280 | Direct [`XMLHttpRequest` interop](https://github.com/emscripten-forge/requests-wasm-polyfill/blob/0.3.0/requests/api.py#L41) in 281 | [sync](https://github.com/emscripten-forge/requests-wasm-polyfill/blob/0.3.0/requests/api.py#L27) mode. 282 | 283 |
286 | 287 | 288 | 289 | Standalone and server-side runtimes (mostly WASI and WASI-Socket-enabled), incl containers, FaaS, Edge Computing, etc 290 | ------------------------------------------------------------------------------------------------------------ 291 | 292 | 293 | ### AssemblyScript 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 313 | 331 | 337 | 342 | 347 | 353 | 361 | 362 | 363 | 375 | 395 | 400 | 406 | 412 | 417 | 424 | 425 |
Product / ImplementationTLDR: UsageTLDR: Example codeDocOnline demoWASM RuntimeInternals: method to do real request
302 | 303 | [wasi-experimental-http](https://www.npmjs.com/package/@deislabs/wasi-experimental-http) 304 | 305 | > [!CAUTION] 306 | > [Repo](https://github.com/deislabs/wasi-experimental-http) was archived on Feb 22, 2024. 307 | 308 | 309 | > [!TIP] 310 | > Use [wasi-http](README.md#assemblyscript-wasi-http) instead. 311 | 312 | 314 | 315 | ```typescript 316 | import { 317 | Method, RequestBuilder, Response 318 | } from "@deislabs/wasi-experimental-http"; 319 | import { Console } from "as-wasi/assembly"; 320 | 321 | let resp = new RequestBuilder("https://httpbin.org/anything") 322 | .header("User-Agent", "wasm32-wasi-http") 323 | .method(Method.GET) 324 | .send(); 325 | 326 | let text = String.UTF8.decode(resp.bodyReadAll().buffer); 327 | Console.log(text); 328 | ``` 329 | 330 | 332 | 333 | * [Example 1](https://github.com/dev-wasm/dev-wasm-ts/blob/a7eb8737aa12b87f55c60acd6d3dd8be0c9d8508/http/main.ts#L15) 334 | * [Example 2](https://github.com/fermyon/spin-kitchensink/blob/c0d0f2b0487df0cb9f151b7dd8f7cd13f9ab1087/assemblyscript-outbound-http/index.ts#L11) _from [old](https://github.com/fermyon/spin/pull/699) Spin_ 335 | 336 | 338 | 339 | [Readme](https://github.com/dev-wasm/dev-wasm-ts/blob/a7eb8737aa12b87f55c60acd6d3dd8be0c9d8508/http/README.md#experimental-http-client-example) 340 | 341 | 343 | 344 | [Dev Container](https://github.com/codespaces/new?hide_repo_select=true&ref=wasi-experimental-http&repo=656267188) _created by brendandburns_ 345 | 346 | 348 | 349 | Wasmtime with integrated `wasi-experimental-http` crate, e.g. [brendandburns's fork](https://github.com/brendandburns/wasmtime/commit/e2a567c4ca38190a74a7eca62cf65892547f2f3b) 350 | or [**old** Spin](https://github.com/fermyon/spin/pull/699) 351 | 352 | 354 | 355 | [Importing](https://github.com/dev-wasm/dev-wasm-ts/blob/a7eb8737aa12b87f55c60acd6d3dd8be0c9d8508/http/package.json#L18) 356 | [npm package](https://www.npmjs.com/package/@deislabs/wasi-experimental-http) which [calls](https://github.com/deislabs/wasi-experimental-http/blob/v0.5.0/crates/as/index.ts#L202) 357 | [imported](https://github.com/deislabs/wasi-experimental-http/blob/v0.5.0/crates/as/raw.ts#L113) 358 | [host function](https://github.com/deislabs/wasi-experimental-http/blob/8291baece45cc51e18e69d7d5ad39ca20744e9f9/crates/wasi-experimental-http-wasmtime/src/lib.rs#L238) implemented in [wasi-experimental-http-wasmtime](https://github.com/deislabs/wasi-experimental-http/tree/8291baece45cc51e18e69d7d5ad39ca20744e9f9/crates/wasi-experimental-http-wasmtime) Wasmtime's WASI module. 359 | 360 |
364 | 365 | [brendandburns/wasi-http-ts](https://github.com/brendandburns/wasi-http-ts) 366 | 367 | > [!CAUTION] 368 | > [Repo](https://github.com/deislabs/wasi-experimental-http) was archived on Feb 22, 2024. 369 | 370 | 371 | > [!TIP] 372 | > Use [wasi-http](README.md#assemblyscript-wasi-http) instead. 373 | 374 | 376 | 377 | ```typescript 378 | // Identical to wasi-experimental-http currently 379 | // Needs `npm i https://github.com/brendandburns/wasi-http-ts` 380 | import { 381 | Method, RequestBuilder 382 | } from "@brendandburns/wasi-http-ts"; 383 | import { Console } from "as-wasi/assembly"; 384 | 385 | let resp = new RequestBuilder("https://httpbin.org/anything") 386 | .header("User-Agent", "wasm32-wasi-http") 387 | .method(Method.GET) 388 | .send(); 389 | 390 | let text = String.UTF8.decode(resp.bodyReadAll().buffer); 391 | Console.log(text); 392 | ``` 393 | 394 | 396 | 397 | <-- 398 | 399 | 401 | 402 | [Readme](https://github.com/dev-wasm/dev-wasm-ts/blob/a7eb8737aa12b87f55c60acd6d3dd8be0c9d8508/http/README.md#experimental-http-client-example) 403 | _from dev-wasm-ts_ 404 | 405 | 407 | 408 | Possible with 409 | [Dev Container](https://github.com/codespaces/new?hide_repo_select=true&ref=wasi-experimental-http&repo=656267188) _created by brendandburns_ 410 | 411 | 413 | 414 | Wasmtime with integrated `wasi-experimental-http` crate, e.g. [brendandburns's fork](https://github.com/brendandburns/wasmtime/commit/e2a567c4ca38190a74a7eca62cf65892547f2f3b) 415 | 416 | 418 | 419 | Using [client lib](https://github.com/brendandburns/wasi-http-ts) which [calls](https://github.com/brendandburns/wasi-http-ts/blob/1f8c7d7e48a79575df080a77fe589cf5cf2309ac/index.ts#L202) 420 | [imported](https://github.com/brendandburns/wasi-http-ts/blob/1f8c7d7e48a79575df080a77fe589cf5cf2309ac/raw.ts#L113) 421 | [host function](https://github.com/deislabs/wasi-experimental-http/blob/8291baece45cc51e18e69d7d5ad39ca20744e9f9/crates/wasi-experimental-http-wasmtime/src/lib.rs#L238) implemented in [wasi-experimental-http-wasmtime](https://github.com/deislabs/wasi-experimental-http/tree/8291baece45cc51e18e69d7d5ad39ca20744e9f9/crates/wasi-experimental-http-wasmtime) Wasmtime's WASI module. 422 | 423 |
426 | 427 | 428 | 429 | ### C# / .Net 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 449 | 462 | 467 | 472 | 477 | 482 | 488 | 489 |
Product / ImplementationTLDR: UsageTLDR: Example codeDocOnline demoWASM RuntimeInternals: method to do real request
438 | 439 | [wasi-experimental-http](https://crates.io/crates/wasi-experimental-http) 440 | 441 | > [!CAUTION] 442 | > [Repo](https://github.com/deislabs/wasi-experimental-http) was archived on Feb 22, 2024. 443 | 444 | 445 | > [!TIP] 446 | > Use [wasi-http](README.md#csharp-wasi-http) instead. 447 | 448 | 450 | 451 | ```csharp 452 | using Wasi.Http; 453 | 454 | var client = new HttpClient(new WasiHttpHandler()); 455 | var result = await client.GetAsync("https://httpbin.org/anything", 456 | System.Threading.CancellationToken.None); 457 | var content = await result.Content.ReadAsStringAsync(); 458 | Console.WriteLine(content); 459 | ``` 460 | 461 | 463 | 464 | [Example](https://github.com/dev-wasm/dev-wasm-dotnet/blob/a08955929b18352c1ff4916a3ecd5aca9237539c/http/Program.cs#L34) 465 | 466 | 468 | 469 | [Readme](https://github.com/dev-wasm/dev-wasm-dotnet/blob/a08955929b18352c1ff4916a3ecd5aca9237539c/http/README.md#experimental-http-client-example) 470 | 471 | 473 | 474 | [Dev Container](https://github.com/codespaces/new?hide_repo_select=true&ref=wasi-experimental-http&repo=650329121) _created by brendandburns_ 475 | 476 | 478 | 479 | Wasmtime with integrated `wasi-experimental-http` crate, e.g. [brendandburns's fork](https://github.com/brendandburns/wasmtime/commit/e2a567c4ca38190a74a7eca62cf65892547f2f3b) 480 | 481 | 483 | 484 | [Calling](https://github.com/dev-wasm/dev-wasm-dotnet/blob/a08955929b18352c1ff4916a3ecd5aca9237539c/http/WasiHttpHandler.cs#L158) [imported](https://github.com/dev-wasm/dev-wasm-dotnet/blob/a08955929b18352c1ff4916a3ecd5aca9237539c/http/WasiHttpExperimental.cs#L25) via [C level](https://github.com/dev-wasm/dev-wasm-dotnet/blob/a08955929b18352c1ff4916a3ecd5aca9237539c/http/req.h#L26) 485 | [bindings](https://github.com/dev-wasm/dev-wasm-dotnet/blob/a08955929b18352c1ff4916a3ecd5aca9237539c/http/wasi_http.c#L93) the [host function](https://github.com/deislabs/wasi-experimental-http/blob/8291baece45cc51e18e69d7d5ad39ca20744e9f9/crates/wasi-experimental-http-wasmtime/src/lib.rs#L238) implemented in [wasi-experimental-http-wasmtime](https://github.com/deislabs/wasi-experimental-http/tree/8291baece45cc51e18e69d7d5ad39ca20744e9f9/crates/wasi-experimental-http-wasmtime) Wasmtime's WASI module. 486 | 487 |
490 | 491 | 492 | 493 | ### C / C++ 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | 513 | 540 | 545 | 550 | 555 | 560 | 565 | 566 |
Product / ImplementationTLDR: UsageTLDR: Example codeDocOnline demoWASM RuntimeInternals: method to do real request
502 | 503 | [wasi-experimental-http](https://crates.io/crates/wasi-experimental-http) 504 | 505 | > [!CAUTION] 506 | > [Repo](https://github.com/deislabs/wasi-experimental-http) was archived on Feb 22, 2024. 507 | 508 | 509 | > [!TIP] 510 | > Use [wasi-http](README.md#cpp-wasi-http) instead. 511 | 512 | 514 | 515 | ```C 516 | #include "req.h" 517 | #include 518 | #include 519 | 520 | const char* url = "https://httpbin.org/anything"; 521 | const char* headers = "User-agent: wasm32-wasi-http"; 522 | size_t length = 1024 * 1024; 523 | char* buffer = (char*) malloc(length); 524 | uint16_t code; 525 | ResponseHandle handle; 526 | 527 | HttpError err = req(url, strlen(url), "GET", 3, headers, 528 | strlen(headers), "", 0, &code, &handle); 529 | 530 | size_t written; 531 | err = bodyRead(handle, buffer, length, &written); 532 | close(handle); 533 | 534 | printf("%s\n", buffer); 535 | 536 | free(buffer); 537 | ``` 538 | 539 | 541 | 542 | [Example](https://github.com/dev-wasm/dev-wasm-c/blob/37e5fcc2cad204ed2534762e81bbceaa32399952/http/main.c#L14) 543 | 544 | 546 | 547 | [Readme](https://github.com/dev-wasm/dev-wasm-c/blob/37e5fcc2cad204ed2534762e81bbceaa32399952/http/README.md#experimental-http-client-example) 548 | 549 | 551 | 552 | [Dev Container](https://github.com/codespaces/new?hide_repo_select=true&ref=wasi-experimental-http&repo=648389246) _created by brendandburns_ 553 | 554 | 556 | 557 | Wasmtime with integrated `wasi-experimental-http` crate, e.g. [brendandburns's fork](https://github.com/brendandburns/wasmtime/commit/e2a567c4ca38190a74a7eca62cf65892547f2f3b) 558 | 559 | 561 | 562 | [Calling](https://github.com/dev-wasm/dev-wasm-c/blob/37e5fcc2cad204ed2534762e81bbceaa32399952/http/main.c#L14) [imported](https://github.com/dev-wasm/dev-wasm-c/blob/37e5fcc2cad204ed2534762e81bbceaa32399952/http/req.h#L26) [host function](https://github.com/deislabs/wasi-experimental-http/blob/8291baece45cc51e18e69d7d5ad39ca20744e9f9/crates/wasi-experimental-http-wasmtime/src/lib.rs#L238) implemented in [wasi-experimental-http-wasmtime](https://github.com/deislabs/wasi-experimental-http/tree/8291baece45cc51e18e69d7d5ad39ca20744e9f9/crates/wasi-experimental-http-wasmtime) Wasmtime's WASI module. 563 | 564 |
567 | 568 | 569 | 570 | ### Golang (Tinygo) 571 | 572 | 573 | 574 | 575 | 576 | 577 | 578 | 590 | 605 | 610 | 615 | 620 | 625 | 630 | 631 |
Product / ImplementationTLDR: UsageTLDR: Example codeDocOnline demoWASM RuntimeInternals: method to do real request
579 | 580 | [wasi-experimental-http](https://crates.io/crates/wasi-experimental-http) 581 | 582 | > [!CAUTION] 583 | > [Repo](https://github.com/deislabs/wasi-experimental-http) was archived on Feb 22, 2024. 584 | 585 | 586 | > [!TIP] 587 | > Use [wasi-http](README.md#golang-wasi-http) instead. 588 | 589 | 591 | 592 | ```go 593 | response, err := Request( 594 | "https://httpbin.org/anything", "GET", 595 | "User-agent: wasm32-wasi-http", "") 596 | defer response.Close() 597 | 598 | body, err := response.Body() 599 | if err == nil { 600 | println(string(body)) 601 | } 602 | ``` 603 | 604 | 606 | 607 | [Example](https://github.com/dev-wasm/dev-wasm-go/blob/d7482362e292598bdb04493a6b664272a60e9c71/http/main.go#L8) 608 | 609 | 611 | 612 | [Readme](https://github.com/dev-wasm/dev-wasm-go/blob/d7482362e292598bdb04493a6b664272a60e9c71/http/README.md#experimental-http-client-example) 613 | 614 | 616 | 617 | [Dev Container](https://github.com/codespaces/new?hide_repo_select=true&ref=wasi-experimental-http&repo=648324699) _created by brendandburns_ 618 | 619 | 621 | 622 | Wasmtime with integrated `wasi-experimental-http` crate, e.g. [brendandburns's fork](https://github.com/brendandburns/wasmtime/commit/e2a567c4ca38190a74a7eca62cf65892547f2f3b) 623 | 624 | 626 | 627 | [Calling](https://github.com/dev-wasm/dev-wasm-go/blob/d7482362e292598bdb04493a6b664272a60e9c71/http/req.go#L64) [imported](https://github.com/dev-wasm/dev-wasm-go/blob/d7482362e292598bdb04493a6b664272a60e9c71/http/req.go#L36-L38) [host function](https://github.com/deislabs/wasi-experimental-http/blob/8291baece45cc51e18e69d7d5ad39ca20744e9f9/crates/wasi-experimental-http-wasmtime/src/lib.rs#L238) implemented in [wasi-experimental-http-wasmtime](https://github.com/deislabs/wasi-experimental-http/tree/8291baece45cc51e18e69d7d5ad39ca20744e9f9/crates/wasi-experimental-http-wasmtime) Wasmtime's WASI module. 628 | 629 |
632 | 633 | 634 | 635 | ### Rust 636 | 637 | 638 | 639 | 640 | 641 | 642 | 643 | 644 | 657 | 672 | 677 | 682 | 683 | 688 | 693 | 694 |
Product / ImplementationTLDR: UsageTLDR: Example codeDocOnline demoWASM RuntimeInternals: method to do real request
645 | 646 | 647 | [wasi-experimental-http](https://crates.io/crates/wasi-experimental-http) 648 | 649 | > [!CAUTION] 650 | > [Repo](https://github.com/deislabs/wasi-experimental-http) was archived on Feb 22, 2024. 651 | 652 | 653 | > [!TIP] 654 | > Use [wasi-http](README.md#wasi-http) instead. 655 | 656 | 658 | 659 | ```rust 660 | use http; 661 | use wasi_experimental_http; 662 | 663 | let req = http::request::Builder::new() 664 | .uri("https://httpbin.org/anything").body(None).unwrap(); 665 | let resp = wasi_experimental_http::request(req); 666 | let data = std::str::from_utf8(&resp.body_read_all().unwrap()) 667 | .unwrap().to_string(); 668 | println!("{}", data); 669 | ``` 670 | 671 | 673 | 674 | [Test](https://github.com/deislabs/wasi-experimental-http/blob/8291baece45cc51e18e69d7d5ad39ca20744e9f9/tests/rust/src/lib.rs#L7) 675 | 676 | 678 | 679 | [Doc](https://docs.rs/wasi-experimental-http/0.10.0/wasi_experimental_http/) 680 | 681 | 684 | 685 | Wasmtime with integrated `wasi-experimental-http` crate, e.g. [brendandburns's fork](https://github.com/brendandburns/wasmtime/commit/e2a567c4ca38190a74a7eca62cf65892547f2f3b) 686 | 687 | 689 | 690 | [Calling](https://github.com/deislabs/wasi-experimental-http/blob/v0.5.0/crates/wasi-experimental-http/src/raw.rs#L180) [imported](https://github.com/deislabs/wasi-experimental-http/blob/v0.5.0/crates/wasi-experimental-http/src/raw.rs#L163-L165) Wasmtime's [host function](https://github.com/deislabs/wasi-experimental-http/blob/8291baece45cc51e18e69d7d5ad39ca20744e9f9/crates/wasi-experimental-http-wasmtime/src/lib.rs#L238). The actual request is [here](https://github.com/deislabs/wasi-experimental-http/blob/8291baece45cc51e18e69d7d5ad39ca20744e9f9/crates/wasi-experimental-http-wasmtime/src/lib.rs#L516). 691 | 692 |
695 | 696 | 697 | 698 | ### Zig 699 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 718 | 742 | 747 | 752 | 757 | 762 | 770 | 771 |
Product / ImplementationTLDR: UsageTLDR: Example codeDocOnline demoWASM RuntimeInternals: method to do real request
707 | 708 | [wasi-experimental-http](https://crates.io/crates/wasi-experimental-http) 709 | 710 | > [!CAUTION] 711 | > [Repo](https://github.com/deislabs/wasi-experimental-http) was archived on Feb 22, 2024. 712 | 713 | 714 | > [!TIP] 715 | > Use wasi-http instead. 716 | 717 | 719 | 720 | ```zig 721 | var gp_all = std.heap.GeneralPurposeAllocator(.{}){}; 722 | const allocator = gp_all.allocator(); 723 | var status: u16 = 0; 724 | var handle: u32 = 0; 725 | 726 | _ = request("https://httpbin.org/anything", "GET", "", "", &status, &handle); 727 | defer _ = close(@bitCast(i32, handle)); 728 | 729 | var headers_buffer = try allocator.alloc(u8, 1024); 730 | var header_len: u32 = 0; 731 | _ = header(handle, "content-length", headers_buffer, &header_len); 732 | const length = try std.fmt.parseInt(u32, headers_buffer[0..header_len], 10); 733 | var buffer = try allocator.alloc(u8, length + 1); 734 | defer allocator.free(buffer); 735 | 736 | var written: u32 = 0; 737 | _ = body_read(handle, &buffer[0], @bitCast(i32, buffer.len), &written); 738 | try std.io.getStdOut().writer().print("{s}\n", .{buffer[0..written]}); 739 | ``` 740 | 741 | 743 | 744 | [Example](https://github.com/dev-wasm/dev-wasm-zig/blob/84c2edf33e025103aae4d0861177585cc56fac8e/src/http.zig#L32) 745 | 746 | 748 | 749 | [Doc](https://docs.rs/wasi-experimental-http/0.10.0/wasi_experimental_http/) 750 | 751 | 753 | 754 | [Dev Container](https://codespaces.new/dev-wasm/dev-wasm-zig) _by brendandburns_ 755 | 756 | 758 | 759 | Wasmtime with integrated `wasi-experimental-http` crate, e.g. [brendandburns's fork](https://github.com/brendandburns/wasmtime/commit/e2a567c4ca38190a74a7eca62cf65892547f2f3b) 760 | 761 | 763 | 764 | [Calling](https://github.com/dev-wasm/dev-wasm-zig/blob/84c2edf33e025103aae4d0861177585cc56fac8e/src/http.zig#L17) 765 | [imported](https://github.com/dev-wasm/dev-wasm-zig/blob/84c2edf33e025103aae4d0861177585cc56fac8e/src/http.zig#L1) 766 | Wasmtime's [host function](https://github.com/deislabs/wasi-experimental-http/blob/8291baece45cc51e18e69d7d5ad39ca20744e9f9/crates/wasi-experimental-http-wasmtime/src/lib.rs#L238). 767 | The actual request is [here](https://github.com/deislabs/wasi-experimental-http/blob/8291baece45cc51e18e69d7d5ad39ca20744e9f9/crates/wasi-experimental-http-wasmtime/src/lib.rs#L516). 768 | 769 |
772 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 vasilev 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. --------------------------------------------------------------------------------