This interface defines a handler of incoming HTTP Requests. It should be exported by components which can respond to HTTP Requests.
Types
use resource incoming-requestsince 0.2.0
Represents an incoming HTTP Request.
method: func() -> methodsince 0.2.0Returns the method of the incoming request.
path-with-query: func() -> option<string>since 0.2.0Returns the path with query parameters from the request, as a string.
scheme: func() -> option<scheme>since 0.2.0Returns the protocol scheme from the request.
headers: func() -> headerssince 0.2.0Get the
headersassociated with the request.The returned
headersresource is immutable:set,append, anddeleteoperations will fail withheader-error.immutable.The
headersreturned are a child resource: it must be dropped before the parentincoming-requestis dropped. Dropping thisincoming-requestbefore all children are dropped will trap.consume: func() -> result<incoming-body>since 0.2.0Gives the
incoming-bodyassociated with this request. Will only return success at most once, and subsequent calls will return error.
use resource response-outparamsince 0.2.0
Represents the ability to send an HTTP Response.
This resource is used by the wasi:http/incoming-handler interface to
allow a Response to be sent corresponding to the Request provided as the
other argument to incoming-handler.handle.
set: static func( param: response-outparam, response: result<outgoing-response, error-code>, )since 0.2.0Set the value of the
response-outparamto either send a response, or indicate an error.This method consumes the
response-outparamto ensure that it is called at most once. If it is never called, the implementation will respond with an error.The user may provide an
errortoresponseto allow the implementation determine how to respond with an HTTP error response.
Functions
handle: func(request: incoming-request, response-out: response-outparam)since 0.2.0
This function is invoked with an incoming HTTP Request, and a resource
response-outparam which provides the capability to reply with an HTTP
Response. The response is sent by calling the response-outparam.set
method, which allows execution to continue after the response has been
sent. This enables both streaming to the response body, and performing other
work.
The implementor of this function must write a response to the
response-outparam before returning, or else the caller will respond
with an error on its behalf.
WIT
/// This interface defines a handler of incoming HTTP Requests. It should
/// be exported by components which can respond to HTTP Requests.
@since(version = 0.2.0)
interface incoming-handler {
@since(version = 0.2.0)
use types.{incoming-request, response-outparam};
/// This function is invoked with an incoming HTTP Request, and a resource
/// `response-outparam` which provides the capability to reply with an HTTP
/// Response. The response is sent by calling the `response-outparam.set`
/// method, which allows execution to continue after the response has been
/// sent. This enables both streaming to the response body, and performing other
/// work.
///
/// The implementor of this function must write a response to the
/// `response-outparam` before returning, or else the caller will respond
/// with an error on its behalf.
@since(version = 0.2.0)
handle: func(request: incoming-request, response-out: response-outparam);
}