Details

Language / Topic
rustRust
Category
Libraries

Rules

balanced
- Create a `reqwest::Client` once and reuse it — it manages connection pools, TLS sessions, and cookie stores internally.
- Use `.json::<T>()` for response deserialization and `.json(&body)` on the builder for request serialization — requires `serde` features enabled.
- Handle errors with `reqwest::Error` — check `.is_timeout()`, `.is_connect()`, `.status()` for specific failure types before retrying.
- Set timeouts on the client: `Client::builder().timeout(Duration::from_secs(30)).build()`.
- Use `response.error_for_status()` to convert HTTP errors into `Result::Err`.
- Use `.header()` for custom headers, `.bearer_auth()` for JWT, `.basic_auth()` for basic auth.
- Use `reqwest::multipart::Form` for file uploads with multipart encoding.