mhuesch / reqwasm

HTTP requests library for WASM Apps

Home Page:https://crates.io/crates/reqwasm

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Reqwasm

crates.io docs.rs licence

HTTP requests library for WASM Apps. It provides idiomatic Rust bindings for the web_sys fetch and WebSocket API

Examples

HTTP

let resp = Request::get("/path")
    .send()
    .await
    .unwrap();
assert_eq!(resp.status(), 200);

WebSocket

let ws = WebSocket::open("wss://echo.websocket.org").unwrap();

let (mut sender, mut receiver) = (ws.sender, ws.receiver);

spawn_local(async move {
    while let Some(m) = receiver.next().await {
        match m {
            Ok(Message::Text(m)) => console_log!("message", m),
            Ok(Message::Bytes(m)) => console_log!("message", format!("{:?}", m)),
            Err(e) => {}
        }
    }
});

spawn_local(async move {
    sender.send(Message::Text("test".to_string())).await.unwrap();
})

Contributions

Your PRs and Issues are welcome. Note that all the contribution submitted by you, shall be licensed as MIT or APACHE 2.0 at your choice, without any additional terms or conditions.

About

HTTP requests library for WASM Apps

https://crates.io/crates/reqwasm

License:Other


Languages

Language:Rust 100.0%