deislabs/wasi-experimental-http

Rust: complete HTTP request / response support

radu-matei opened this issue · 4 comments

It would be very nice if the Rust API didn't reimplement the entire HTTP request / response structures from scratch.

The http crate is already used by hyper and reqwest, and it would make sense to allow users to construct requests and get responses back.

This means we would have to decompose its fields (body, method, query params, headers) into buffers and their lengths before making the host call, but users could use the request builder to simplify things:

pub fn request<T, U>(req: Request<T>) -> Result<Response<U>, Error> {
    todo!()
}

Not sure what the type constraints on T and U should be here (most likely Serialize + Sized, but that would have to be checked).

Update: 1596496 added support for request and response headers.

Status codes are next.

#6 adds support for status codes.

I'm leaning towards explicitly requiring that both request and response bodies to be Vec<u8>, as this might be the easiest way to represent generic bodies.

As of #11, the Rust crate for guest modules has complete support for HTTP requests and responses.

There are still other things not working (any sort of streaming, or other bodies), but for now, this should be enough to validate the idea of the library.

Closing for now, but I suspect we will open several other issues related to more concrete requests for the Rust crate.