Sans-IO HTTP vocabulary for MoonBit SDKs: request/response types, a Transport trait, an incremental SSE parser and a scripted fake transport. No dependencies; runs on every backend.
pub(open) trait BodyStream {
async fn read_some(Self) -> Bytes? raise HttpError
fn close(Self) -> Unit
}pub(open) trait Transport {
async fn send(Self, Request) -> Response raise HttpError
async fn send_stream(Self, Request) -> (ResponseHead, &BodyStream) raise HttpError
}test {
let headers = @http.Headers::from_array([("Accept", "text/plain")])
assert_eq(headers.get("ACCEPT"), Some("text/plain"))
}test {
let request = @http.Request::post("/items")
.header("Accept", "application/json")
.body_text("hello")
assert_eq(request.body, b"hello")
}test {
let response : @http.Response = {
status: 200,
headers: @http.Headers::new(),
body: b"hello",
}
assert_eq(response.text(), "hello")
assert_true(response.is_success())
}Install
Download zipSans-IO HTTP vocabulary for MoonBit SDKs: request/response types, a Transport trait, an incremental SSE parser and a scripted fake transport. No dependencies; runs on every backend.