Search

Lib.rs

› Network programming | Asynchronous
#sse-stream #sse #qubit

qubit-http

General-purpose HTTP infrastructure for Rust with unified client semantics, secure logging, and built-in SSE decoding

by Haixing Hu

  • Install
  • API reference
  • GitHub repo (qubit-ltd)

7 unstable releases (3 breaking)

new 0.5.2 May 9, 2026
0.5.1 May 3, 2026
0.4.2 May 1, 2026
0.4.0 Apr 28, 2026
0.2.0 Apr 14, 2026

#935 in Network programming

Apache-2.0

315KB
5K SLoC

Rust 4.5K SLoC // 0.1% comments Shell 533 SLoC // 0.0% comments

Qubit HTTP (rs-http)

CircleCI Coverage Status Crates.io Docs.rs Rust License 中文文档

Documentation: User Guide | API Reference

qubit-http is a production-oriented Rust HTTP infrastructure crate for building API clients with consistent behavior across services.

It builds on reqwest and provides the common pieces most API clients need: request construction, timeouts, retries, cancellation, streaming responses, SSE, logging, and unified errors.

Why Use It

Use qubit-http when you need:

  • one request execution flow for buffered, lazy, and streaming response bodies
  • shared timeout, retry, cancellation, proxy, redirect, and logging behavior
  • consistent error handling through HttpError, HttpErrorKind, and RetryHint
  • built-in helpers for JSON, form, multipart, NDJSON, streaming, and SSE
  • config-driven client creation for service-level consistency

For full examples and advanced options, read the User Guide.

Installation

[dependencies]
qubit-http = "0.5"
http = "1"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }

Some examples in the user guide use optional helper crates such as serde, serde_json, futures-util, and qubit-config.

Quick Start

This example uses httpbin.org, so you can run it without starting a local test server.

use http::Method;
use qubit_http::{HttpClientFactory, HttpClientOptions};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut options = HttpClientOptions::new();
    options.set_base_url("https://httpbin.org")?;
    options.add_header("x-client-id", "demo")?;

    let client = HttpClientFactory::new().create(options)?;

    let request = client
        .request(Method::GET, "/anything")
        .query_param("from", "readme")
        .build();

    let mut response = client.execute(request).await?;
    println!("status = {}", response.status());
    println!("text = {}", response.text().await?);
    Ok(())
}

Common Next Steps

Task Read
Create clients from defaults, options, or config User Guide
Build JSON, form, multipart, NDJSON, or stream request bodies User Guide
Add default headers, header injectors, and interceptors User Guide
Configure timeouts, retries, cancellation, and Retry-After handling User Guide
Read bytes, text, JSON, streams, or SSE chunks User Guide
Configure logging, sensitive headers, proxy, redirects, and IPv4-only mode User Guide
Handle status, transport, timeout, cancellation, decode, and retry errors User Guide

Core API At A Glance

Type Purpose
HttpClientFactory Creates clients from defaults, explicit options, or config.
HttpClientOptions Holds client-level defaults for base URL, headers, timeouts, retry, logging, proxy, redirects, connection pool, and SSE decoding.
HttpClient Executes requests and applies headers, injectors, interceptors, retry, logging, and SSE reconnect helpers.
HttpRequestBuilder Builds method, path, query, headers, body, and request-level overrides.
HttpResponse Exposes response metadata and lazy readers for bytes, text, JSON, streams, and SSE.

Project Scope

  • qubit-http is built on top of reqwest; it focuses on a stable shared HTTP surface rather than exposing every reqwest API.
  • Response bodies are read lazily unless TRACE response-body logging is enabled.
  • Built-in request retry covers failures before HttpResponse is returned. Stream body errors after return are surfaced to the caller.
  • SSE reconnect has a dedicated API: HttpClient::execute_sse_with_reconnect(...).

Contributing

Issues and pull requests are welcome.

Please keep contributions focused and easy to review:

  • open an issue for bug reports, design questions, or larger feature proposals
  • keep pull requests scoped to one behavior change, fix, or documentation update
  • follow the Rust coding style
  • include tests when changing runtime behavior
  • update the user guide or README when public API behavior changes

By contributing to this project, you agree that your contribution will be licensed under the same license as the project.

License

Licensed under the Apache License, Version 2.0.

Dependencies

~23–33MB
~503K SLoC

  • async-stream
  • bytes+serde
  • futures-util
  • http 1.4
  • httpdate
  • parse-display 0.10
  • qubit-config
  • qubit-datatype
  • qubit-error
  • qubit-function 0.11
  • qubit-retry+tokio
  • reqwest 0.13+json+stream+query+socks
  • serde+derive
  • serde_json
  • strum 0.28+derive
  • thiserror 2.0
  • tokio+time+net+macros
  • tokio-util+rt
  • tracing
  • url
  • dev tracing-subscriber+fmt
Related: qubit-lock, qubit-serde, qubit-function, qubit-atomic, qubit-config, qubit-value, qubit-cas, qubit-mime, qubit-batch, qubit-metadata, qubit-command, qubit-dcl, qubit-clock, qubit-datatype, qubit-codec, qubit-executor, qubit-argument
See also: sse-stream, eventsource-stream, http, http-body, opencode_rs, turul-http-mcp-server, opencode-sdk, previa-main, http-type, http-request, calleen

Lib.rs is an unofficial list of Rust/Cargo crates, created by kornelski. It contains data from multiple sources, including heuristics, and manually curated data. Content of this page is not necessarily endorsed by the authors of the crate. This site is not affiliated with nor endorsed by the Rust Project. If something is missing or incorrect, please file a bug.