Skip to main content

Crate reqx

Crate reqx 

Source
Expand description

reqx is an internal HTTP transport crate for API SDKs with HTTP/1.1 + HTTP/2 support.

§Quick Start

use std::time::Duration;
use reqx::prelude::{HttpClient, RetryPolicy};
use serde::Deserialize;

#[derive(Debug, Deserialize)]
struct CreateItemResponse {
    id: String,
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = HttpClient::builder("https://api.example.com")
        .client_name("my-sdk")
        .request_timeout(Duration::from_secs(3))
        .total_timeout(Duration::from_secs(8))
        .retry_policy(
            RetryPolicy::standard()
                .max_attempts(3)
                .base_backoff(Duration::from_millis(100))
                .max_backoff(Duration::from_millis(800)),
        )
        .try_build()?;

    let created: CreateItemResponse = client
        .post("/v1/items")
        .idempotency_key("create-item-001")?
        .json(&serde_json::json!({ "name": "demo" }))?
        .send_json()
        .await?;

    println!("created id={}", created.id);
    Ok(())
}
  • Use RetryPolicy::standard() for SDK traffic.
  • Set both request timeout and total timeout.
  • For POST retries, always set idempotency_key(...).

Modules§

blocking_blocking
prelude

Structs§

AdaptiveConcurrencyPolicy
AsyncResumableUploader_async
BlockingHttpClient_blocking
BlockingHttpClientBuilder_blocking
BlockingHttpResponseStream_blocking
BlockingResumableUploader
CircuitBreakerPolicy
HttpClient_async
HttpClientBuilder_async
HttpClientMetricsSnapshot
HttpResponse
HttpResponseStream_async
PermissiveRetryEligibility
RateLimitPolicy
RedirectPolicy
RequestContext
ResumableUploadCheckpoint
ResumableUploadOptions
ResumableUploadResult
RetryBudgetPolicy
RetryDecision
RetryPolicy
StrictRetryEligibility
UploadedPart

Enums§

HttpClientError
HttpClientErrorCode
PartChecksumAlgorithm
ResumableUploadError
ServerThrottleScope
TimeoutPhase
TlsBackend
TransportErrorKind

Constants§

RESUMABLE_UPLOAD_CHECKPOINT_VERSION

Traits§

AsyncResumableUploadBackend_async
BlockingResumableUploadBackend
HttpInterceptor
RetryClassifier
RetryEligibility

Type Aliases§

ReqxResult