Debian Codegraph @

crates/wit-component/tests/interfaces/wasi-http/handler.wit

raw
1 /// This interface defines a handler of incoming HTTP Requests. It should
2 /// be exported by components which can respond to HTTP Requests.
3 interface incoming-handler {
4 use types.{incoming-request, response-outparam};
5
6 /// This function is invoked with an incoming HTTP Request, and a resource
7 /// `response-outparam` which provides the capability to reply with an HTTP
8 /// Response. The response is sent by calling the `response-outparam.set`
9 /// method, which allows execution to continue after the response has been
10 /// sent. This enables both streaming to the response body, and performing other
11 /// work.
12 ///
13 /// The implementor of this function must write a response to the
14 /// `response-outparam` before returning, or else the caller will respond
15 /// with an error on its behalf.
16 handle: func(
17 request: incoming-request,
18 response-out: response-outparam
19 );
20 }
21
22 /// This interface defines a handler of outgoing HTTP Requests. It should be
23 /// imported by components which wish to make HTTP Requests.
24 interface outgoing-handler {
25 use types.{
26 outgoing-request, request-options, future-incoming-response, error-code
27 };
28
29 /// This function is invoked with an outgoing HTTP Request, and it returns
30 /// a resource `future-incoming-response` which represents an HTTP Response
31 /// which may arrive in the future.
32 ///
33 /// The `options` argument accepts optional parameters for the HTTP
34 /// protocol's transport layer.
35 ///
36 /// This function may return an error if the `outgoing-request` is invalid
37 /// or not allowed to be made. Otherwise, protocol errors are reported
38 /// through the `future-incoming-response`.
39 handle: func(
40 request: outgoing-request,
41 options: option<request-options>
42 ) -> result<future-incoming-response, error-code>;
43 }