Skip to content

Commit 5a56ac5

Browse files
committed
Rework 0.3 handlers and worlds
- Add a `client` interface with a `send` function matching `handle` - Replace the `imports` world's `handler` import with `client` - Replace the `proxy` world with `service` - Add a `middleware` world
1 parent d2a63e1 commit 5a56ac5

File tree

3 files changed

+38
-24
lines changed

3 files changed

+38
-24
lines changed

wit-0.3.0-draft/client.wit

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/// This interface defines an HTTP client. It may be imported by components that
2+
/// wish to send HTTP Requests or it may be composed with a `handler` to process
3+
/// requests without any use of a network. In addition, it may be exported by
4+
/// components to wrap another `client` as with "client interceptors".
5+
interface client {
6+
use types.{request, response, error-code};
7+
8+
/// This function may be used to either send an outgoing request over the
9+
/// network or to forward it to another component.
10+
send: async func(
11+
request: request,
12+
) -> result<response, error-code>;
13+
}

wit-0.3.0-draft/handler.wit

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
1-
/// This interface defines a handler of HTTP Requests. It may be imported by
2-
/// components which wish to send HTTP Requests and also exported by components
3-
/// which can respond to HTTP Requests. In addition, it may be used to pass
4-
/// a request from one component to another without any use of a network.
1+
/// This interface defines a handler of HTTP Requests. It may be exported by
2+
/// components which can respond to HTTP Requests. In addition, it may be
3+
/// imported by components to wrap another `handler` as with "middleware".
54
interface handler {
65
use types.{request, response, error-code};
76

8-
/// When exported, this function may be called with either an incoming
9-
/// request read from the network or a request synthesized or forwarded by
10-
/// another component.
11-
///
12-
/// When imported, this function may be used to either send an outgoing
13-
/// request over the network or pass it to another component.
7+
/// This function may be called with either an incoming request read from the
8+
/// network or a request synthesized or forwarded by another component.
149
handle: async func(
1510
request: request,
1611
) -> result<response, error-code>;
17-
}
12+
}
Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package wasi:http@0.3.0-rc-2025-09-16;
22

3-
/// The `wasi:http/imports` world imports all the APIs for HTTP proxies.
3+
/// The `wasi:http/imports` world imports all the APIs for HTTP services.
44
/// It is intended to be `include`d in other worlds.
55
world imports {
6-
/// HTTP proxies have access to time and randomness.
6+
/// HTTP services have access to time and randomness.
77
include wasi:clocks/imports@0.3.0-rc-2025-09-16;
88
import wasi:random/random@0.3.0-rc-2025-09-16;
99

10-
/// Proxies have standard output and error streams which are expected to
10+
/// Services have standard output and error streams which are expected to
1111
/// terminate in a developer-facing console provided by the host.
1212
import wasi:cli/stdout@0.3.0-rc-2025-09-16;
1313
import wasi:cli/stderr@0.3.0-rc-2025-09-16;
@@ -18,19 +18,15 @@ world imports {
1818
/// when this import is properly removed.
1919
import wasi:cli/stdin@0.3.0-rc-2025-09-16;
2020

21-
/// This is the default handler to use when user code simply wants to make an
21+
/// This is the default `client` to use when user code simply wants to make an
2222
/// HTTP request (e.g., via `fetch()`).
23-
///
24-
/// This may also be used to pass synthesized or forwarded requests to another
25-
/// component.
26-
import handler;
23+
import client;
2724
}
2825

29-
/// The `wasi:http/proxy` world captures a widely-implementable intersection of
30-
/// hosts that includes HTTP forward and reverse proxies. Components targeting
31-
/// this world may concurrently stream in and out any number of incoming and
32-
/// outgoing HTTP requests.
33-
world proxy {
26+
/// The `wasi:http/service` world captures a broad category of HTTP services
27+
/// including web applications, API servers, and proxies. It may be `include`d
28+
/// in more specific worlds such as `wasi:http/gateway`.
29+
world service {
3430
include imports;
3531

3632
/// The host delivers incoming HTTP requests to a component by calling the
@@ -42,3 +38,13 @@ world proxy {
4238
/// another component.
4339
export handler;
4440
}
41+
42+
/// The `wasi:http/middleware` world captures HTTP services that forward HTTP
43+
/// Requests to another handler. Components may implement this world to allow
44+
/// them to participate in handler "chains" where a Request flows through
45+
/// handlers on its way to some "terminal" service and corresponding Responses
46+
/// flow in the opposite direction.
47+
world middleware {
48+
include service;
49+
import handler;
50+
}

0 commit comments

Comments
 (0)