Surf is the Rust HTTP client we've always wanted. It's completely modular, and
built directly for async/await
. Whether it's a quick script, or a
cross-platform SDK, Surf will make it work.
Client
interface```rust
let mut res = surf::get("https://httpbin.org/get").await?; dbg!(res.body_string().await?);
```
It's also possible to skip the intermediate Response
, and access the response
type directly.
```rust
dbg!(surf::get("https://httpbin.org/get").recv_string().await?);
```
Both sending and receiving JSON is real easy too.
```rust
struct Ip { ip: String }
let uri = "https://httpbin.org/post"; let data = &Ip { ip: "129.0.0.1".into() }; let res = surf::post(uri).bodyjson(data)?.await?; asserteq!(res.status(), 200);
let uri = "https://api.ipify.org?format=json"; let Ip { ip } = surf::get(uri).recv_json().await?; assert!(ip.len() > 10);
```
And even creating streaming proxies is no trouble at all.
```rust
let reader = surf::get("https://img.fyi/q6YvNqP").await?; let res = surf::post("https://box.rs/upload").body(reader).await?;
```
sh
$ cargo add surf
This crate makes use of a single instance of unsafe
in order to make the WASM
backend work despite the Send
bounds. This is safe because WASM targets
currently have no access to threads. Once they do we'll be able to drop this
implementation, and use a parked thread instead and move to full multi-threading
in the process too.
Want to join us? Check out our "Contributing" guide and take a look at some of these issues:
Special thanks to prasannavl for donating the
crate name, and sagebind for creating an easy to
use async
curl client that saved us countless hours.
MIT OR Apache-2.0