wasm-lang/example/http

20 lines
435 B
Text

use std::http::{HttpClient, EventSource};
use std::json;
fn main(ctx: Context) -> Result<(), Error> {
let http = HttpClient::new(ctx.net);
let request = http.post("https://example.com/generate")
.header("content-type", "application/json")
.body(json::to_bytes(.{
hello: "world",
}))
.send()?;
let events = EventSource::new(request);
for event in events {
ctx.log.info("got event: {}", event.data);
}
Ok(())
}