Skip to content

Conversation

pchickey
Copy link
Contributor

@pchickey pchickey commented Sep 18, 2025

This is a major rewrite of the http api to provide compatibility with the http_body::Body trait. This trait is used throughout the Rust http ecosystem (e.g. hyper, reqwest, axum) to provide an async streaming representation of bodies with trailers.

There is a new wstd::http::Body struct that is a concrete representation for bodies.

The http server entrypoint now looks like:

#[wstd::http_server]
async fn main(request: Request<Body>) -> Result<Response<Body>, Error> {
   ...
}

http::Client now looks like

impl Client {
    pub async fn send<B: Into<Body>>(&self, req: Request<B>) -> Result<Response<Body>, Error> { ... }
   ...
}

There is no more IntoBody trait. To construct a Body, there are:

  • From<B: http_body::Body> for Body (simplified - definition for full signature)
  • from_string(s: impl Into<String>) -> Self
  • from_bytes(b: impl Into<Bytes>) -> Self
  • from_json(data: impl serde::Serialize) -> Result<Self, serde_json::Error>
  • from_input_stream(r: wstd::io::AsyncInputStream) -> Self
  • internal to wstd, created from a wasi-http incoming-body resource. This variation allows efficient forwarding to an outgoing-body where body streaming can skip copying in and out of the guest, via wstd::io::copy.

The ways to consume a Body are:

@pchickey pchickey force-pushed the pch/server_result_body branch from 512947a to c1451ba Compare October 10, 2025 00:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant