http-client

A set of Rust rules for building HTTP clients, software that sends requests to web services, with the reqwest library.

In plain words
What is it for?
Use it when adding simple requests, complex integrations, or service clients to a Rust application.
Why use it?
It provides a consistent approach to request timeouts, errors, retries, authentication, monitoring, and tests.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/tyrchen/cursor-rust-rules/http-client
Clone the repo
git clone --depth 1 https://github.com/tyrchen/cursor-rust-rules

Made for: Cursor.

Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 1,619 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.01619
Opus 5 $0.00000 $0.00809
Sonnet 5 $0.00000 $0.00324
Haiku 4.5 $0.00000 $0.00162

Measured 2d ago against content hash adb7494ad711, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

http-client scanned grade A with 0 findings against 26 rules in 11 categories โ€” prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency โ€” measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/rust/features/http-client.mdc ยท 257 lines

How it starts

The opening of the file, as written. The whole thing โ€” 257 lines โ€” stays where its author put it; the contents beside it link to each section on GitHub.

๐ŸŒ HTTP CLIENT BEST PRACTICES

TL;DR: Modern HTTP client patterns using reqwest with proper error handling, timeouts, and security configurations.

๐Ÿ” HTTP CLIENT ARCHITECTURE STRATEGY

graph TD
    Start["HTTP Client Requirements"] --> ClientType{"Client<br>Usage Pattern?"}

    ClientType -->|Simple Requests| SimpleClient["Simple Request Pattern"]
    ClientType -->|Complex Integration| AdvancedClient["Advanced Client Pattern"]
    ClientType -->|Service Integration| ServiceClient["Service Client Pattern"]

    SimpleClient --> BasicConfig["Basic Configuration"]
    AdvancedClient --> BuilderPattern["Builder Pattern"]
    ServiceClient --> TypedClient["Typed Client"]

    BasicConfig --> ErrorHandling["Error Handling"]
    BuilderPattern --> ErrorHandling
    TypedClient --> ErrorHandling

    ErrorHandling --> RetryLogic["Retry Logic"]
    RetryLogic --> Authentication["Authentication"]
    Authentication --> Monitoring["Request Monitoring"]

    Monitoring --> Testing["Client Testing"]
    Testing --> Production["Production HTTP Client"]

    style Start fill:#4da6ff,stroke:#0066cc,color:white
    style SimpleClient fill:#4dbb5f,stroke:#36873f,color:white
    style AdvancedClient fill:#ffa64d,stroke:#cc7a30,color:white
    style ServiceClient fill:#d94dbb,stroke:#a3378a,color:white

๐Ÿ”ง REQWEST CONFIGURATION

Standard Dependencies

# Cargo.toml - HTTP client configuration
[dependencies]
reqwest = { version = "0.12", default-features = false, features = [
    "charset",
    "rustls-tls-webpki-roots",
    "http2",
    "json",
    "cookies",
    "gzip",
    "brotli",
    "zstd",
    "deflate"
] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tokio = { version = "1.45", features = ["macros", "rt-multi-thread"] }
anyhow = "1.0"
thiserror = "2.0"
url = "2.5"

๐Ÿ—๏ธ CLIENT BUILDER PATTERN

Configurable HTTP Client

use reqwest::{Client, ClientBuilder, Response};
use serde::{Deserialize, Serialize};
use std::time::Duration;
use url::Url;

pub struct HttpClient {
    client: Client,
    base_url: Url,
    default_timeout: Duration,
}

impl HttpClient {
    pub fn builder() -> HttpClientBuilder {
        HttpClientBuilder::new()
    }

    pub async fn get<T>(&self, path: &str) -> Result<T, HttpError>
    where
        T: for<'de> Deserialize<'de>,
    {
        let url = self.base_url.join(path)?;

        let response = self
            .client
            .get(url)
            .timeout(self.default_timeout)
            .send()
            .await?;

        self.handle_response(response).await
    }

    pub async fn post<T, B>(&self, path: &str, body: &B) -> Result<T, HttpError>
    where
        T: for<'de> Deserialize<'de>,
        B: Serialize,
    {
        let url = self.base_url.join(path)?;

        let response = self
            .client
            .post(url)
            .json(body)
            .timeout(self.default_timeout)
            .send()
            .await?;

        self.handle_response(response).await
    }

    async fn handle_response<T>(&self, response: Response) -> Result<T, HttpError>
    where
        T: for<'de> Deserialize<'de>,
    {
        let status = response.status();

        if status.is_success() {
            let text = response.text().await?;
            serde_json::from_str(&text).map_err(|e| HttpError::Deserialization {
                error: e.to_string(),
                body: text,
            })
        } else {
            let body = response.text().await.unwrap_or_default();
            Err(HttpError::UnexpectedStatus {
                status: status.as_u16(),
                body,
            })
        }
    }
}

pub struct HttpClientBuilder {
    base_url: Option<String>,
    timeout: Option<Duration>,
    user_agent: Option<String>,
    headers: Vec<(String, String)>,
    accept_invalid_certs: bool,
}

impl HttpClientBuilder {
    pub fn new() -> Self {
        Self {
            base_url: None,
            timeout: Some(Duration::from_secs(30)),
            user_agent: Some("rust-http-client/1.0".to_string()),
            headers: Vec::new(),
            accept_invalid_certs: false,
        }
    }

    pub fn base_url(mut self, url: &str) -> Self {
        self.base_url = Some(url.to_string());
        self
    }

    pub fn timeout(mut self, timeout: Duration) -> Self {
        self.timeout = Some(timeout);
        self
    }

    pub fn build(self) -> Result<HttpClient, HttpError> {
        let base_url = self.base_url
            .ok_or_else(|| HttpError::Configuration("Base URL is required".to_string()))?;

        let mut client_builder = ClientBuilder::new()
            .danger_accept_invalid_certs(self.accept_invalid_certs);

        if let Some(timeout) = self.timeout {
            client_builder = client_builder.timeout(timeout);
        }

        if let Some(user_agent) = &self.user_agent {
            client_builder = client_builder.user_agent(user_agent);
        }

        let client = client_builder.build()?;
        let parsed_url = Url::parse(&base_url)?;

        Ok(HttpClient {
            client,
            base_url: parsed_url,
            default_timeout: self.timeout.unwrap_or(Duration::from_secs(30)),
        })
    }
}

Read the full file on GitHub ยท 257 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen ยท 257 lines ยท 0 tokens per session scan A adb7494ad711

Subscribe to this mod's changes

http-client is a cursor rule published in the GitHub repository tyrchen/cursor-rust-rules (27 stars, last pushed 1y ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 1,619 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.