pub struct SimklResponse {
pub status_code: u16,
pub headers: HashMap<String, String>,
pub body: String,
}Expand description
Owned, pre-buffered HTTP response returned by the caller’s HTTP client.
The simkl crate is transport-agnostic — the caller collects the
status, headers, and body from reqwest/ureq/hyper/…, wraps them
here, and uses SimklResponse::json / SimklResponse::pagination_info
to decode them.
Fields§
§status_code: u16Numeric HTTP status code (e.g. 200, 404, 503).
headers: HashMap<String, String>Response headers as returned by the transport. Header-name lookup
via SimklResponse::pagination_info is case-insensitive.
body: StringRaw response body — usually JSON, decoded on demand via
SimklResponse::json.
Implementations§
Source§impl SimklResponse
impl SimklResponse
Sourcepub fn json<T: DeserializeOwned>(&self) -> Result<T>
pub fn json<T: DeserializeOwned>(&self) -> Result<T>
Deserialise the body as JSON into T.
Sourcepub fn json_value(&self) -> Result<Value>
pub fn json_value(&self) -> Result<Value>
Deserialise the body as an untyped serde_json::Value.
Sourcepub fn is_success(&self) -> bool
pub fn is_success(&self) -> bool
true for HTTP 2xx status codes.
Sourcepub fn is_client_error(&self) -> bool
pub fn is_client_error(&self) -> bool
true for HTTP 4xx status codes.
Sourcepub fn is_server_error(&self) -> bool
pub fn is_server_error(&self) -> bool
true for HTTP 5xx status codes.
Sourcepub fn pagination_info(&self) -> Option<PaginationInfo>
pub fn pagination_info(&self) -> Option<PaginationInfo>
Parse pagination metadata from the X-Pagination-* response headers.
The Simkl API returns pagination as HTTP headers, not in the body:
| Header | Meaning |
|---|---|
X-Pagination-Page | Current page (1-based) |
X-Pagination-Limit | Items per page |
X-Pagination-Page-Count | Total pages |
X-Pagination-Item-Count | Total items |
Returns None when none of the headers are present (non-paginated endpoint).
Header lookup is case-insensitive per RFC 7230 §3.2; many HTTP client libraries lower-case header names before exposing them to the caller.