Skip to main content

SimklResponse

Struct SimklResponse 

Source
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: u16

Numeric 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: String

Raw response body — usually JSON, decoded on demand via SimklResponse::json.

Implementations§

Source§

impl SimklResponse

Source

pub fn json<T: DeserializeOwned>(&self) -> Result<T>

Deserialise the body as JSON into T.

Source

pub fn json_value(&self) -> Result<Value>

Deserialise the body as an untyped serde_json::Value.

Source

pub fn is_success(&self) -> bool

true for HTTP 2xx status codes.

Source

pub fn is_client_error(&self) -> bool

true for HTTP 4xx status codes.

Source

pub fn is_server_error(&self) -> bool

true for HTTP 5xx status codes.

Source

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:

HeaderMeaning
X-Pagination-PageCurrent page (1-based)
X-Pagination-LimitItems per page
X-Pagination-Page-CountTotal pages
X-Pagination-Item-CountTotal 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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.