pub trait ResponseExt {
// Required methods
fn rate_limit_info(&self) -> Option<RateLimitInfo>;
fn next_page_url(&self) -> Option<String>;
fn problem_json_or_json<T: DeserializeOwned>(
self,
) -> impl Future<Output = Result<T, ApiError>> + Send;
}Expand description
Extension methods for reqwest::Response.
Required Methods§
Sourcefn rate_limit_info(&self) -> Option<RateLimitInfo>
fn rate_limit_info(&self) -> Option<RateLimitInfo>
Parse X-RateLimit-* headers into a RateLimitInfo.
Returns None if the required rate-limit headers are absent or
unparseable.
§Example
use api_bones_reqwest::ResponseExt;
let resp = reqwest::get("https://api.example.com/").await?;
if let Some(rl) = resp.rate_limit_info() {
println!("remaining: {}", rl.remaining);
}Sourcefn next_page_url(&self) -> Option<String>
fn next_page_url(&self) -> Option<String>
Parse the RFC 5988 Link: <url>; rel="next" header and return the
URL for the next page, if present.
§Example
use api_bones_reqwest::ResponseExt;
let resp = reqwest::get("https://api.example.com/items").await?;
if let Some(next) = resp.next_page_url() {
println!("next: {next}");
}Sourcefn problem_json_or_json<T: DeserializeOwned>(
self,
) -> impl Future<Output = Result<T, ApiError>> + Send
fn problem_json_or_json<T: DeserializeOwned>( self, ) -> impl Future<Output = Result<T, ApiError>> + Send
Consume the response, returning the deserialized body.
- If the status code indicates an error (
>= 400) and theContent-Typecontainsapplication/problem+json, the body is parsed as anApiErrorand returned asErr. - Otherwise the body JSON is deserialized into
Tand returned asOk.
§Errors
Returns Err(ApiError) for:
- Problem+JSON error responses (
>= 400with correct content type). - Non-Problem+JSON error responses (
>= 400). - JSON deserialization failures.
- Network / transport errors from reqwest.
§Example
use api_bones_reqwest::{RequestBuilderExt, ResponseExt};
let resp = reqwest::Client::new()
.get("https://api.example.com/items")
.send()
.await
.map_err(|e| api_bones::ApiError::bad_request(e.to_string()))?;
let body: serde_json::Value = resp.problem_json_or_json().await?;Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.