Crate surf[][src]

Expand description

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 Client interface
  • Fully streaming requests and responses
  • TLS enabled by default (native tls or rustls)
  • Built on async-std (with optional tokio support)


let mut res = surf::get("").await?;

It’s also possible to skip the intermediate Response, and access the response type directly.


Both sending and receiving JSON is real easy too.

#[derive(Deserialize, Serialize)]
struct Ip {
    ip: String

let uri = "";
let data = &Ip { ip: "".into() };
let res = surf::post(uri).body_json(data)?.await?;
assert_eq!(res.status(), 200);

let uri = "";
let Ip { ip } = surf::get(uri).recv_json().await?;
assert!(ip.len() > 10);

And even creating streaming proxies is no trouble at all.

let req = surf::get("").await?;
let body = surf::http::Body::from_reader(req, None);
let res = surf::post("").body(body).await?;

Setting configuration on a client is also straightforward.

use std::convert::TryInto;
use std::time::Duration;
use surf::{Client, Config};
use surf::Url;

let client: Client = Config::new()
let mut res = client.get("/").await?;
println!("{}", res.body_string().await?);


The following features are available. The default features are curl-client, middleware-logger, and encoding

  • curl-client (default): use curl (through isahc) as the HTTP backend.
  • h1-client: use async-h1 as the HTTP backend with native TLS for HTTPS.
  • h1-client-rustls: use async-h1 as the HTTP backend with rustls for HTTPS.
  • hyper-client: use hyper ( as the HTTP backend.
  • wasm-client: use window.fetch as 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.


pub use http_types as http;


Middleware types

Miscellaneous utilities.


A streaming HTTP body.

An HTTP client, capable of sending Requests and running a middleware stack.

Configuration for surf::Clients and their underlying HTTP clients.

An error occurred while decoding a response body to a string.

The error type for HTTP operations.

An HTTP request, returns a Response.

Request Builder

An HTTP response, returned by Request.

A parsed URL record.


HTTP response status codes.


An abstract HTTP client.

Provides the status method for Result and Option.


Construct a new Client, capable of sending Requests and running a middleware stack.

Perform a one-off CONNECT request.

Perform a one-off DELETE request.

Perform a one-off GET request.

Perform a one-off HEAD request.

Perform a one-off OPTIONS request.

Perform a one-off PATCH request.

Perform a one-off POST request.

Perform a one-off PUT request.

Perform a one-off TRACE request.

Type Definitions

A specialized Result type for Surf.