Expand description
A small blocking HTTP client on top of libcurl: curl’s HTTP stack as a Rust library, for programs that have to work where they are deployed.
No async runtime, one libcurl handle per thread with connection reuse,
the machine’s proxies, certificate store, ~/.netrc and single sign-on
honoured, request bodies held in memory once, and multipart/form-data
in both directions.
use curlite::Multipart;
let response = curlite::get("https://httpbin.org/get")
.query("page", "2")
.send()?;
println!("{} {}", response.status(), response.text()?);
let response = curlite::post("https://httpbin.org/post")
.multipart(
Multipart::new()
.text("description", "report")
.file("file", "report.pdf", mime::APPLICATION_PDF, std::fs::read("report.pdf")?),
)
.send()?;Bodies are set with Request::body (raw bytes with a MIME type),
Request::body_reader (streamed from a file or other reader),
Request::form (application/x-www-form-urlencoded) or
Request::multipart. Responses are read into memory by
Request::send, streamed to a writer by Request::send_to or read
on demand through Request::send_reader. Multipart responses are
split with Response::parts. A Client holds headers, timeouts,
proxy and TLS settings shared by several requests, and
Request::to_curl prints any request as a curl command line.
§Features
json:Request::jsonandResponse::jsonviaserde_json.log: libcurl’s verbose output aslog::trace!records with targetcurlite, when that level is enabled.http2,static-curl,static-ssl,rustls: passed through to thecurlcrate, see below.
§TLS
TLS comes from libcurl. By default the system libcurl is linked
dynamically, with whatever TLS library it was built against. The
static-curl, static-ssl and rustls features are passed through to
the curl crate to build and link libcurl statically instead.
Re-exports§
pub use mime;
Modules§
- header
- HTTP header types
Structs§
- Bytes
- A cheaply cloneable and sliceable chunk of contiguous memory.
- Client
- Defaults shared by several requests: headers, timeouts and redirect handling. Requests built from a client start with these values and can override each of them.
- Header
Map - A specialized multimap for header names and values.
- Header
Name - Represents an HTTP header field name
- Header
Value - Represents an HTTP header field value.
- Method
- The Request Method (VERB)
- Mime
- A parsed mime or media type.
- Multipart
- A
multipart/form-databody. - Progress
- Bytes moved so far in one transfer, see
Request::on_progress. - Request
- A request under construction. Created with
Request::new, one of the free functions (get,post, …) or aClient, and sent withRequest::sendorRequest::send_to. - Response
- A response, read completely into memory (or, for
Request::send_to, with the body already written out). - Response
Part - One part of a
multipart/*response body, seeResponse::parts. - Response
Reader - A response whose body is read on demand, see
Request::send_reader. - Status
Code - An HTTP status code (
status-codein RFC 9110 et al.).
Enums§
- Auth
- HTTP authentication, see
Request::auth. Credentials are handed to libcurl, which answers the server’s challenge; onlyBasicandBearerare sent without being asked. - Error
- Errors returned by this crate.
- Http
Version - The HTTP version to ask libcurl for, see
Request::http_version.
Functions§
- delete
- Starts a
DELETErequest. - get
- Starts a
GETrequest. - head
- Starts a
HEADrequest. - patch
- Starts a
PATCHrequest. - post
- Starts a
POSTrequest. - put
- Starts a
PUTrequest.