Expand description
This module provides utilities for writing HTTP servers and clients using the WASI HTTP API.
It’s inspired by the WASI 0.3 proposal for https://github.com/WebAssembly/wasi-http and will be supported until the release of wasi:http@0.3.0. After that, this module will likely be deprecated.
use wasmcloud_component::http;
struct Component;
http::export!(Component);
// Implementing the [`Server`] trait for a component
impl http::Server for Component {
fn handle(_request: http::IncomingRequest) -> http::Result<http::Response<impl http::OutgoingBody>> {
Ok(http::Response::new("Hello from Rust!"))
}
}
Modules§
- header
- HTTP header types
- method
- The HTTP request method
- response
- HTTP response types.
- uri
- URI component of request and response lines
Macros§
- export
- Macro to export
wasi::exports::http::incoming_handler::Guest
implementation for a type that implementsServer
. This aims to be as similar as possible to [wasi::http::proxy::export!
].
Structs§
- Header
Map - A set of HTTP headers
- Header
Name - Represents an HTTP header field name
- Header
Value - Represents an HTTP header field value.
- Incoming
Body - Wraps the incoming body of a request which just contains
the stream and the body of the request itself. The bytes of the body
are only read into memory explicitly. The implementation of
OutgoingBody
for this type will read the bytes from the stream and write them to the output stream. - Method
- The Request Method (VERB)
- Read
Body - Wraps a body, which implements Read
- Request
- Represents an HTTP request.
- Response
- Represents an HTTP response
- Status
Code - An HTTP status code (
status-code
in RFC 9110 et al.). - Uri
- The URI component of a request.
Enums§
- Error
Code - These cases are inspired by the IANA HTTP Proxy Error Types: https://www.iana.org/assignments/http-proxy-status/http-proxy-status.xhtml#table-http-proxy-error-types
- Fields
ToHeader MapError - Response
Error
Traits§
- Outgoing
Body - Trait for implementing a type that can be written to an outgoing HTTP response body.
- Server
- Trait for implementing an HTTP server WebAssembly component that receives a
IncomingRequest
and returns aResponse
.