Surf the web - HTTP client framework
Surf is a Rust HTTP client built for ease-of-use and multi-HTTP-backend flexibility. Whether it's a quick script, or a cross-platform SDK, Surf will make it work.
- Extensible through a powerful middleware system
- Multiple HTTP back-ends that can be chosen
- Reuses connections through a configurable
- Fully streaming requests and responses
- TLS enabled by default (native tls or rustls)
- Built on async-std (with optional tokio support)
let mut res = get.await?; dbg!;
It's also possible to skip the intermediate
Response, and access the response type directly.
Both sending and receiving JSON is real easy too.
let uri = "https://httpbin.org/post"; let data = &Ip ; let res = post.body_json?.await?; assert_eq!; let uri = "https://api.ipify.org?format=json"; let Ip = get.recv_json.await?; assert!;
And even creating streaming proxies is no trouble at all.
let req = get.await?; let body = from_reader; let res = post.body.await?;
Setting configuration on a client is also straightforward.
use TryInto; use Duration; use ; use Url; let client: Client = new .set_base_url .set_timeout .try_into?; let mut res = client.get.await?; println!;
The following features are available. The default features are
isahc) as the HTTP backend.
async-h1as the HTTP backend with native TLS for HTTPS.
async-h1as the HTTP backend with
hyper(hyper.rs) as the HTTP backend.
window.fetchas the HTTP backend.
middleware-logger(default): enables logging requests and responses using a middleware.
encoding(default): enables support for body encodings other than utf-8.
Install OpenSSL -
- Ubuntu -
sudo apt install libssl-dev
- Fedora -
sudo dnf install openssl-devel
Make sure your rust is up to date using:
With cargo add installed :
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
async curl client that saved us countless hours.
MIT OR Apache-2.0