4 releases

0.2.1 Aug 22, 2024
0.2.0 Aug 22, 2024
0.1.1 Aug 21, 2024
0.1.0 Aug 21, 2024

#387 in WebAssembly

41 downloads per month

MIT license

16KB
291 lines

teahttpd

an unsophisticated (fetch wrapper) http client for wasm

ok pls propose something because this ductape plane is running on a motive of "should works, would works and it works!"

how to use

    let _res: web_sys::Request = teahttp::TeaRequest::get("/api/something")
        .header("Accept", "application/json")?
        .clone()
        .slice_body(&encoded)
        .invoke()
        .await?;

    let _res: web_sys::Request = teahttp::TeaRequest::post("/api/upload")
        .header("Content-Type", "application/octet-stream")?
        .header("Content-Length", &encoded.len().to_string())?
        .clone()
        .slice_body(&encoded)
        .invoke()
        .await?;

todo if needed

  • better error handling
  • serde
  • umm diy and wrap this?

lib.rs:

teahttp

Very simple but work well for WASM environment. As many http client tend to screw up WebWorker global, this ehttp inspired crate is to help. Although it seems to be a good alt, many things considerably manual.

Few example to figure things out

    TeaRequest::get("/api/something")
       .invoke()
       .await? // web_sys::Response

    let some_body = b"lorem ipsum dolor si amet";
    TeaRequest::post("/api/upload")
        .header("Content-Length", some_body)?
        .slice_body(some_body.as_slice() /* &[u8] */)
        .invoke()
        .await?

    TeaRequest::post("/api/submit")
        .header("Content-Length", &12.to_string())?
        .str_body("Hello World!" /* &str */)
        .invoke()
        .await?

Have fun

Dependencies

~7–10MB
~181K SLoC

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy