Skip to content

Commit 1077c9e

Browse files
committed
Rework 0.3 handlers and worlds
- Add an `outgoing-handler` interface with the same type as `handler` - Replace the `imports` world's `handler` import with `outgoing-handler` - Replace the `proxy` world with `service` - Add a `middleware` world
1 parent d2a63e1 commit 1077c9e

File tree

2 files changed

+40
-24
lines changed

2 files changed

+40
-24
lines changed

wit-0.3.0-draft/handler.wit

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
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>;
1712
}
13+
14+
/// This interface defines a handler of "outgoing" HTTP Requests. It may be
15+
/// imported by components that wish to send HTTP Requests or it may be
16+
/// composed with a `handler` to process requests without any use of a network.
17+
/// In addition, it may be exported by components to wrap another
18+
/// `outgoing-handler` as with "client interceptors".
19+
interface outgoing-handler {
20+
use types.{request, response, error-code};
21+
22+
/// This function may be used to either send an outgoing request over the
23+
/// network or to forward it to another component.
24+
handle: async func(
25+
request: request,
26+
) -> result<response, error-code>;
27+
}
Lines changed: 20 additions & 14 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
22-
/// 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;
21+
/// This is the default `outgoing-handler` to use when user code simply wants
22+
/// to make an HTTP request (e.g., via `fetch()`).
23+
import outgoing-handler;
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)