componentized/directory

wasi:http

interface dependency

A WASI API for sending and receiving HTTP requests and responses.

interface incoming-handler wasi:http/incoming-handler@0.2.3 since 0.2.0

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

from wasi:http/types@0.2.3

Represents an incoming HTTP Request.

  • functionmethod: func() -> methodsince 0.2.0

    Returns the method of the incoming request.

  • functionpath-with-query: func() -> option<string>since 0.2.0

    Returns the path with query parameters from the request, as a string.

  • functionscheme: func() -> option<scheme>since 0.2.0

    Returns the protocol scheme from the request.

  • functionauthority: func() -> option<string>since 0.2.0

    Returns the authority of the Request's target URI, if present.

  • functionheaders: func() -> headerssince 0.2.0

    Get the headers associated with the request.

    The returned headers resource is immutable: set, append, and delete operations will fail with header-error.immutable.

    The headers returned are a child resource: it must be dropped before the parent incoming-request is dropped. Dropping this incoming-request before all children are dropped will trap.

  • functionconsume: func() -> result<incoming-body>since 0.2.0

    Gives the incoming-body associated with this request. Will only return success at most once, and subsequent calls will return error.

use resource response-outparamsince 0.2.0

from wasi:http/types@0.2.3

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.

  • static functionset: static func( param: response-outparam, response: result<outgoing-response, error-code>, )since 0.2.0

    Set the value of the response-outparam to either send a response, or indicate an error.

    This method consumes the response-outparam to 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 error to response to allow the implementation determine how to respond with an HTTP error response.

Functions

functionhandle: 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);
}