Expand description
A small, blocking REST client built on libcurl.
The API is a builder centered around Client, with GET as the default method.
Use send as the terminal operation.
§libcurl dependency
curl-rest links to libcurl, so your build needs a libcurl development
package available on the system (for example, installed via your OS package
manager). If you prefer a vendored build or static linking, enable the
appropriate curl/curl-sys features in your application so Cargo
propagates them to this crate.
This crate exposes a few convenience features (default is ssl):
ssl: enable OpenSSL-backed TLS (libcurl’s default).rustls: enable Rustls-backed TLS (disable default features in your dependency to avoid OpenSSL).static-curl: build and link against a bundled libcurl.static-ssl: build and link against a bundled OpenSSL.vendored: enables bothstatic-curlandstatic-ssl.
§Quickstart
let resp = curl_rest::get("https://example.com")?;
println!("Status: {}", resp.status);
for header in &resp.headers {
println!("{}: {}", header.name, header.value);
}
let resp = curl_rest::Client::default()
.post()
.body_json(r#"{"name":"stanley"}"#)
.send("https://example.com/users")?;
println!("{}", String::from_utf8_lossy(&resp.body));§Examples
let resp = curl_rest::Client::default()
.get()
.header(curl_rest::Header::Accept("application/json".into()))
.header(curl_rest::Header::Custom("X-Request-Id".into(), "req-123".into()))
.query_param_kv("page", "1")
.send("https://example.com/api/users")
.expect("request failed");
println!("Status: {}", resp.status);
for header in &resp.headers {
println!("{}: {}", header.name, header.value);
}Structs§
- Client
- Builder for constructing and sending a blocking HTTP request.
- Query
Param - Query parameter represented as a key-value pair.
- Response
- HTTP response container returned by
send. - Response
Header - A single HTTP response header entry.
Enums§
- Body
- Error
- Error type returned by the curl-rest client.
- Header
- Common HTTP headers supported by the client, plus
Customfor non-standard names. - Method
- Supported HTTP methods.
- Status
Code - HTTP status codes defined by RFC 9110 and related specifications.
Functions§
- get
- Sends a GET request using default builder settings.
- get_
with_ headers - Sends a GET request with headers using default builder settings.
- post
- Sends a POST request using default builder settings.
- post_
with_ headers - Sends a POST request with headers using default builder settings.
- request
- Sends a request with the given method and URL using default builder settings.
- request_
with_ headers - Sends a request with the given method, URL, and headers using default builder settings.
Type Aliases§
- Curl
Deprecated