Skip to content

Commit a059ac1

Browse files
committed
Address PR feedback
1 parent a4dc0ac commit a059ac1

File tree

4 files changed

+81
-75
lines changed

4 files changed

+81
-75
lines changed

wit-0.3.0-draft/client.wit

Lines changed: 0 additions & 13 deletions
This file was deleted.

wit-0.3.0-draft/handler.wit

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +0,0 @@
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".
4-
interface handler {
5-
use types.{request, response, error-code};
6-
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.
9-
handle: async func(
10-
request: request,
11-
) -> result<response, error-code>;
12-
}

wit-0.3.0-draft/service.wit

Lines changed: 0 additions & 50 deletions
This file was deleted.

wit-0.3.0-draft/worlds.wit

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package wasi:http@0.3.0-rc-2025-09-16;
2+
3+
/// The `wasi:http/service` world captures a broad category of HTTP services
4+
/// including web applications, API servers, and proxies. It may be `include`d
5+
/// in more specific worlds such as `wasi:http/middleware`.
6+
world service {
7+
/// HTTP services have access to time and randomness.
8+
include wasi:clocks/imports@0.3.0-rc-2025-09-16;
9+
import wasi:random/random@0.3.0-rc-2025-09-16;
10+
11+
/// Services have standard output and error streams which are expected to
12+
/// terminate in a developer-facing console provided by the host.
13+
import wasi:cli/stdout@0.3.0-rc-2025-09-16;
14+
import wasi:cli/stderr@0.3.0-rc-2025-09-16;
15+
16+
/// TODO: this is a temporary workaround until component tooling is able to
17+
/// gracefully handle the absence of stdin. Hosts must return an eof stream
18+
/// for this import, which is what wasi-libc + tooling will do automatically
19+
/// when this import is properly removed.
20+
import wasi:cli/stdin@0.3.0-rc-2025-09-16;
21+
22+
/// This is the default `client` to use when user code simply wants to make an
23+
/// HTTP request (e.g., via `fetch()`).
24+
import client;
25+
26+
/// The host delivers incoming HTTP requests to a component by calling the
27+
/// `handle` function of this exported interface. A host may arbitrarily reuse
28+
/// or not reuse component instance when delivering incoming HTTP requests and
29+
/// thus a component must be able to handle 0..N calls to `handle`.
30+
///
31+
/// This may also be used to receive synthesized or forwarded requests from
32+
/// another component.
33+
export handler;
34+
}
35+
36+
/// The `wasi:http/middleware` world captures HTTP services that forward HTTP
37+
/// Requests to another handler.
38+
///
39+
/// Components may implement this world to allow them to participate in handler
40+
/// "chains" where a Request flows through handlers on its way to some terminal
41+
/// `service` and corresponding Responses flow in the opposite direction.
42+
world middleware {
43+
include service;
44+
import handler;
45+
}
46+
47+
/// This interface defines a handler of HTTP Requests.
48+
///
49+
/// In a `wasi:http/service` this interface is exported to respond to an
50+
/// incoming HTTP Request with a Response.
51+
///
52+
/// In `wasi:http/middleware` this interface is both exported and imported as
53+
/// the "downstream" and "upstream" directions of the middleware chain.
54+
interface handler {
55+
use types.{request, response, error-code};
56+
57+
/// This function may be called with either an incoming request read from the
58+
/// network or a request synthesized or forwarded by another component.
59+
handle: async func(
60+
request: request,
61+
) -> result<response, error-code>;
62+
}
63+
64+
/// This interface defines an HTTP client for sending "outgoing" requests.
65+
///
66+
/// Most components are expected to import this interface to provide the
67+
/// capability to send HTTP requests to arbitrary destinations on a network.
68+
///
69+
/// The type signature of `client.send` is the same as `handler.handle`. This
70+
/// duplication is currently necessary because some Component Model tooling
71+
/// (including WIT itself) is unable to represent a component importing two
72+
/// instances of the same interface.
73+
interface client {
74+
use types.{request, response, error-code};
75+
76+
// This function may be used to either send an outgoing request over the
77+
// network or to forward it to another component.
78+
send: async func(
79+
request: request,
80+
) -> result<response, error-code>;
81+
}

0 commit comments

Comments
 (0)