You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/develop/javascript/networking.md
+7-6Lines changed: 7 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -8,15 +8,16 @@ The QuickJS WasmEdge Runtime supports Node.js's `http` and `fetch` APIs via the
8
8
9
9
The networking API in WasmEdge is non-blocking and hence supports asynchronous I/O-intensive applications. With this API, the JavaScript program can open multiple connections concurrently. It polls those connections or registers async callback functions to process data whenever data comes in, without waiting for any one connection to complete its data transfer. That allows the single-threaded application to handle multiple, multiple concurrent requests.
10
10
11
-
-[Networking](#networking)
12
-
-[Prerequisites](#prerequisites)
13
-
-[Fetch client](#fetch-client)
14
-
-[HTTP server](#http-server)
15
-
-[TCP server and client](#tcp-server-and-client)
11
+
-[Prerequisites](#prerequisites)
12
+
-[Fetch client](#fetch-client)
13
+
-[HTTP server](#http-server)
14
+
-[TCP server and client](#tcp-server-and-client)
16
15
17
16
## Prerequisites
18
17
19
-
[See here](./hello_world#prerequisites)
18
+
[Install WasmEdge](../../start/install.md). To make HTTPS requests, install the [WasmEdge TLS plug-in](../../start/install.md#tls-plug-in).
19
+
20
+
[Install WasmEdge-QuickJS](./hello_world#prerequisites). Make sure that the `modules` directory is located in your local directory where you want to execute the `wasmedge` command.
Copy file name to clipboardExpand all lines: docs/develop/rust/http_service/client.md
+49-27Lines changed: 49 additions & 27 deletions
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
sidebar_position: 1
3
3
---
4
4
5
-
# Client
5
+
# HTTP client
6
6
7
7
WasmEdge allows Rust developers to use APIs they are already familiar with to access the Internet via the HTTP or HTTPS protocols. This chapter will cover HTTP client APIs and libraries to access external web services from your WasmEdge app. For HTTP servers in WasmEdge, please see [the next chapter](server).
8
8
@@ -11,16 +11,15 @@ WasmEdge allows Rust developers to use APIs they are already familiar with to ac
11
11
Before we start, ensure [you have Rust and WasmEdge installed](../setup.md). To make HTTPS requests, install the [WasmEdge TLS plug-in](../../../start/install.md#tls-plug-in).
12
12
:::
13
13
14
-
We will discuss HTTP and HTTPS asynchronous clients with hyper, synchronous clients with http_req, and simple clients with request. All of them are popular Rust crates for networking.
14
+
We will discuss HTTP and HTTPS clients using popular Rust APIs.
15
15
16
-
-[Client](#client)
17
-
-[Asynchronous client with hyper](#asynchronous-client-with-hyper)
18
-
-[Synchronous client with http_req](#synchronous-client-with-http_req)
19
-
-[reqwest client](#reqwest-client)
16
+
-[The hyper API (recommended)](#the-hyper-api)
17
+
-[The http_req API](#the-http_req-api)
18
+
-[The reqwest API](#the-reqwest-api)
20
19
21
-
## Asynchronous client with hyper
20
+
## The hyper API
22
21
23
-
Asynchronous HTTP or HTTPS requests do not block the execution of the calling application. It allows an application to make multiple concurrent HTTP requests and to process responses as they are received. That enables high-performance networking applications in WasmEdge. The [hyper crate](https://crates.io/crates/hyper) is a widely used Rust library to create HTTP and HTTPS networking applications.
22
+
The [hyper crate](https://crates.io/crates/hyper) is a widely used Rust library to create HTTP and HTTPS networking applications. We recommend you use it in WasmEdge applications. A key feature of the `hyper` crate is that it is based on the `tokio` runtime, which supports asynchronous network connections. Asynchronous HTTP or HTTPS requests do not block the execution of the calling application. It allows an application to make multiple concurrent HTTP requests and to process responses as they are received. That enables high-performance networking applications in WasmEdge.
In your Rust application, import [the WasmEdge adapted hyper crate](https://crates.io/crates/hyper_wasi), which uses a special version of single-threaded Tokio that is adapted for WebAssembly. Just add the following line to your Cargo.toml.
44
+
The HTTPS version of the demo is as follows. Make sure that you install the [WasmEdge TLS plug-in](../../../start/install.md#tls-plug-in) first.
In your Rust application, import [the WasmEdge adapted hyper crate](https://crates.io/crates/hyper_wasi), which uses a special version of single-threaded Tokio that is adapted for WebAssembly. Just add the following line to your `Cargo.toml`.
46
57
47
58
```toml
48
59
[dependencies]
49
60
hyper_wasi = "0.15.0"
50
61
```
51
62
52
-
The [Rust example code](https://github.com/WasmEdge/wasmedge_hyper_demo/blob/main/client/src/main.rs) below shows an HTTP or HTTPS GET request.
63
+
The [Rust example code](https://github.com/WasmEdge/wasmedge_hyper_demo/blob/main/client/src/main.rs) below shows an HTTP GET request.
If your WasmEdge application only needs to make sequential requests to external web services, a synchronous client is easier to work with. It allows you to make a request, wait for the response, and move on once the response is fully received. Use the http_req API to make simple synchronous HTTP requests. Build and run [the example](https://github.com/second-state/http_req/) in WasmEdge.
118
+
If your WasmEdge application only needs to make sequential requests to external web services, a synchronous client is easier to work with. It allows you to make a request, wait for the response, and move on once the response is fully received. Use the `http_req` API to make simple synchronous HTTP requests. Build and run [the example](https://github.com/second-state/http_req/) in WasmEdge.
In your Rust application, import the [http_req_wasi](https://crates.io/crates/http_req_wasi) crate, which is compatible with [http_req](https://github.com/jayjamesjay/http_req) at the API level. Just add the following line to your Cargo.toml.
136
+
In your Rust application, import the [http_req_wasi](https://crates.io/crates/http_req_wasi) crate, which is compatible with [http_req](https://github.com/jayjamesjay/http_req) at the API level. Just add the following line to your `Cargo.toml`.
110
137
111
138
```toml
112
139
[dependencies]
113
140
http_req_wasi = "0.10"
114
141
```
115
142
116
-
The example below shows an [HTTP GET request](https://github.com/second-state/http_req/blob/master/examples/get.rs).
143
+
The example below shows an [HTTP GET request](https://github.com/second-state/http_req/blob/master/examples/get.rs). For HTTPS requests, you can [simply change](https://github.com/second-state/http_req/blob/master/examples/get_https.rs) the `http` URL to `https`.
117
144
118
145
```rust
119
146
usehttp_req::request;
@@ -128,7 +155,7 @@ fn main() {
128
155
}
129
156
```
130
157
131
-
And here is an [HTTP POST request](https://github.com/second-state/http_req/blob/master/examples/post.rs).
158
+
And here is an [HTTP POST request](https://github.com/second-state/http_req/blob/master/examples/post.rs). For HTTPS requests, you can [simply change](https://github.com/second-state/http_req/blob/master/examples/post_https.rs) the `http` URL to `https`.
132
159
133
160
```rust
134
161
usehttp_req::request;
@@ -144,14 +171,9 @@ fn main() {
144
171
}
145
172
```
146
173
147
-
<!-- prettier-ignore -->
148
-
:::note
149
-
In order to make HTTPS requests, you need to [install the wasmedge_TLS plug-in](../../../start/install.md#tls-plug-in). You can then run the HTTPS [GET](https://github.com/second-state/http_req/blob/master/examples/get_https.rs) and [POST](https://github.com/second-state/http_req/blob/master/examples/post_https.rs) examples in the example repo.
150
-
:::
151
-
152
-
## reqwest client
174
+
## The reqwest API
153
175
154
-
The reqwest crate is another popular Rust library to create asynchronous HTTP clients. It is built on top of the hyper API. Many developers find it easier to use. Build and run [the example](https://github.com/WasmEdge/wasmedge_reqwest_demo/) in WasmEdge as follows.
176
+
The `reqwest` crate is another popular Rust library to create asynchronous HTTP clients. It is built on top of the `hyper` API. Many developers find it easier to use. But perhaps more importantly, many existing Rust applications use `reqwest`, and you can make them work in WasmEdge by simply replacing the `reqwest` crate with `reqwest_wasi`! Build and run [the example](https://github.com/WasmEdge/wasmedge_reqwest_demo/) in WasmEdge as follows.
In your Rust application, import [the WasmEdge adapted hyper crate](https://crates.io/crates/hyper_wasi), which uses a special version of single-threaded Tokio that is adapted for WebAssembly. Just add the following line to your Cargo.toml.
196
+
In your Rust application, import [the WasmEdge adapted reqwest crate](https://crates.io/crates/reqwest_wasi), which uses a special version of single-threaded Tokio that is adapted for WebAssembly. Just add the following lines to your `Cargo.toml`.
Copy file name to clipboardExpand all lines: docs/develop/rust/http_service/server.md
+9-6Lines changed: 9 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,10 @@ sidebar_position: 2
4
4
5
5
# Server
6
6
7
-
For WasmEdge to become a cloud-native runtime for microservices, it needs to support HTTP servers. By its very nature, the HTTP server is always asynchronous. In this chapter, we will cover simple HTTP servers based on [the wrap API](#the-warp-api), as well as the [low-level hyper API](#the-hyper-api). For HTTP clients in WasmEdge, please see [the previous chapter](client.md).
7
+
For WasmEdge to become a cloud-native runtime for microservices, it needs to support HTTP servers. By its very nature, the HTTP server is always asynchronous (non-blocking -- so that it can handle concurrent requests). This chapter will cover HTTP servers using popular Rust APIs.
8
+
9
+
-[The warp API](#the-warp-api)
10
+
-[The hyper API](#the-hyper-api)
8
11
9
12
<!-- prettier-ignore -->
10
13
:::note
@@ -22,7 +25,7 @@ cd wasmedge_hyper_demo/server-warp
In your Rust application, import the WasmEdge-adapted warp crate, which uses a special version of single-threaded Tokio adapted for WebAssembly. Just add the following lines to your Cargo.toml.
41
+
In your Rust application, import the WasmEdge-adapted `warp_wasi` crate, which uses a special version of single-threaded Tokio adapted for WebAssembly. Just add the following lines to your `Cargo.toml`.
39
42
40
43
```toml
41
44
[dependencies]
@@ -68,7 +71,7 @@ async fn main() {
68
71
69
72
## The hyper API
70
73
71
-
The warp crate is convenient to use. But oftentimes, developers need access to lowerlevel APIs. The hyper crate is an excellent HTTP library for that. Build and run [the example](https://github.com/WasmEdge/wasmedge_hyper_demo/blob/main/server/) in WasmEdge as follows.
74
+
The `warp` crate is convenient to use. But oftentimes, developers need access to lower-level APIs. The `hyper` crate is an excellent HTTP library for that. Build and run [the example](https://github.com/WasmEdge/wasmedge_hyper_demo/blob/main/server/) in WasmEdge as follows.
In your Rust application, import the WasmEdge adapted hyper crate, which uses a special version of single threaded Tokio that is adapted for WebAssembly. Just add the following line to your Cargo.toml.
96
+
In your Rust application, import the WasmEdge adapted `hyper_wasi` crate, which uses a special version of single threaded Tokio that is adapted for WebAssembly. Just add the following lines to your `Cargo.toml`.
Copy file name to clipboardExpand all lines: docs/develop/rust/socket_networking/client.md
+8-5Lines changed: 8 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -2,11 +2,14 @@
2
2
sidebar_position: 1
3
3
---
4
4
5
-
# Client
5
+
# Socket client
6
6
7
-
The [wasmedge_wasi_socket](https://github.com/second-state/wasmedge_wasi_socket) crate enables Rust developers to create networking applications and compile them into WebAssembly for WasmEdge Runtime. One of the key features of WasmEdge is that it supports non-blocking sockets. That allows even a single-threaded WASM application to handle concurrent network requests. For example, while the program is waiting for data to stream in from one connection, it can start or handle another connection.
7
+
It is possible for WasmEdge applications to open TCP/IP or UDP network sockets in the host system to communicate directly with external applications. One of the key features of WasmEdge is that it supports non-blocking sockets. That allows even a single-threaded WASM application to handle concurrent network requests. For example, while the program is waiting for data to stream in from one connection, it can start or handle another connection. The [wasmedge_wasi_socket](https://github.com/second-state/wasmedge_wasi_socket) crate enables Rust developers to work on the network socket level.
8
8
9
-
While there are many possibilities with sockets, we will demonstrate two familiar use cases, [a simple HTTP client](#a-simple-http-client) and [a non-blocking HTTP client application](#a-non-blocking-http-client-example), in this chapter.
9
+
In this chapter, we will show you how to build HTTP clients on TCP sockets. The reason is that the HTTP protocol is relatively simple and could be demonstrated easily. If you use HTTP clients in production, we recommend checking out the [HTTP client](../http_service/client.md) chapter in this book.
10
+
11
+
-[A simple HTTP client based on TCP sockets](#a-simple-http-client)
12
+
-[A non-blocking HTTP client based on TCP sockets](#a-non-blocking-http-client-example)
10
13
11
14
<!-- prettier-ignore -->
12
15
:::note
@@ -24,7 +27,7 @@ cd wasmedge_wasi_socket/http_client/
Copy file name to clipboardExpand all lines: docs/develop/rust/socket_networking/server.md
+7-4Lines changed: 7 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -2,9 +2,12 @@
2
2
sidebar_position: 2
3
3
---
4
4
5
-
# Server
5
+
# Socket server
6
6
7
-
As we described in the [client](client.md) chapter, with the WasmEdge socket API, it is also possible for Rust developers to work directly on the socket level. For WasmEdge to become a cloud-native runtime for microservices, it needs to support HTTP servers. In this chapter, we will discuss[an HTTP server example](#an-http-server-example) and [a non-blocking HTTP server example](#a-non-blocking-http-server-example).
7
+
As we described in the [client](client.md) chapter, with the WasmEdge socket API, it is possible for Rust developers to work directly on the TCP and UDP socket level. In this chapter, we will show how to create HTTP servers with the TCP socket API. We chose HTTP here for demonstration purposes due to the simplicity of the HTTP protocol. If you need a production-ready HTTP server, check out the [HTTP server](../http_service/server.md) chapter.
8
+
9
+
-[An HTTP server example](#an-http-server-example)
10
+
-[A non-blocking HTTP server example](#a-non-blocking-http-server-example)
8
11
9
12
<!-- prettier-ignore -->
10
13
:::note
@@ -22,7 +25,7 @@ cd wasmedge_wasi_socket/http_server
0 commit comments