Skip to main content

Crate curlite

Crate curlite 

Source
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::json and Response::json via serde_json.
  • log: libcurl’s verbose output as log::trace! records with target curlite, when that level is enabled.
  • http2, static-curl, static-ssl, rustls: passed through to the curl crate, 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.
HeaderMap
A specialized multimap for header names and values.
HeaderName
Represents an HTTP header field name
HeaderValue
Represents an HTTP header field value.
Method
The Request Method (VERB)
Mime
A parsed mime or media type.
Multipart
A multipart/form-data body.
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 a Client, and sent with Request::send or Request::send_to.
Response
A response, read completely into memory (or, for Request::send_to, with the body already written out).
ResponsePart
One part of a multipart/* response body, see Response::parts.
ResponseReader
A response whose body is read on demand, see Request::send_reader.
StatusCode
An HTTP status code (status-code in RFC 9110 et al.).

Enums§

Auth
HTTP authentication, see Request::auth. Credentials are handed to libcurl, which answers the server’s challenge; only Basic and Bearer are sent without being asked.
Error
Errors returned by this crate.
HttpVersion
The HTTP version to ask libcurl for, see Request::http_version.

Functions§

delete
Starts a DELETE request.
get
Starts a GET request.
head
Starts a HEAD request.
patch
Starts a PATCH request.
post
Starts a POST request.
put
Starts a PUT request.

Type Aliases§

Result