pub struct HttpResponse {
pub code: u16,
pub headers: HashMap<String, Vec<String>>,
pub body: Value,
pub prev_page_info: Option<String>,
pub next_page_info: Option<String>,
pub api_call_limit: Option<ApiCallLimit>,
pub retry_request_after: Option<f64>,
}Expand description
An HTTP response from the Shopify API.
Contains the response status code, headers, body, and parsed Shopify-specific header values like rate limits and pagination.
Fields§
§code: u16The HTTP status code.
headers: HashMap<String, Vec<String>>Response headers (headers may have multiple values).
body: ValueThe parsed response body.
prev_page_info: Option<String>Page info for the previous page (from Link header).
next_page_info: Option<String>Page info for the next page (from Link header).
api_call_limit: Option<ApiCallLimit>Rate limit information (from X-Shopify-Shop-Api-Call-Limit header).
retry_request_after: Option<f64>Seconds to wait before retrying (from Retry-After header).
Implementations§
Source§impl HttpResponse
impl HttpResponse
Sourcepub fn new(
code: u16,
headers: HashMap<String, Vec<String>>,
body: Value,
) -> Self
pub fn new( code: u16, headers: HashMap<String, Vec<String>>, body: Value, ) -> Self
Creates a new HttpResponse with automatic header parsing.
This constructor parses Shopify-specific headers automatically:
X-Shopify-Shop-Api-Call-Limit->api_call_limitLink->prev_page_info,next_page_infoRetry-After->retry_request_after
Sourcepub const fn is_ok(&self) -> bool
pub const fn is_ok(&self) -> bool
Returns true if the response status code is in the 2xx range.
Sourcepub fn request_id(&self) -> Option<&str>
pub fn request_id(&self) -> Option<&str>
Returns the X-Request-Id header value, if present.
This ID is useful for debugging and should be included in error reports.
Sourcepub fn deprecation_reason(&self) -> Option<&str>
pub fn deprecation_reason(&self) -> Option<&str>
Returns the X-Shopify-API-Deprecated-Reason header value, if present.
When present, this indicates the API endpoint is deprecated and should be updated.
Sourcepub fn deprecation_info(&self) -> Option<ApiDeprecationInfo>
pub fn deprecation_info(&self) -> Option<ApiDeprecationInfo>
Returns structured deprecation information if the response indicates deprecation.
This method parses the X-Shopify-API-Deprecated-Reason header and returns
an ApiDeprecationInfo struct with the deprecation details.
§Example
use shopify_api::HttpResponse;
use std::collections::HashMap;
use serde_json::json;
let mut headers = HashMap::new();
headers.insert(
"x-shopify-api-deprecated-reason".to_string(),
vec!["This endpoint is deprecated".to_string()],
);
let response = HttpResponse::new(200, headers, json!({}));
if let Some(info) = response.deprecation_info() {
println!("Warning: {}", info.reason);
}Sourcepub fn is_deprecated(&self) -> bool
pub fn is_deprecated(&self) -> bool
Returns true if the response indicates a deprecated API endpoint.
This checks for the presence of the X-Shopify-API-Deprecated-Reason header.
§Example
use shopify_api::HttpResponse;
use std::collections::HashMap;
use serde_json::json;
let mut headers = HashMap::new();
headers.insert(
"x-shopify-api-deprecated-reason".to_string(),
vec!["This endpoint is deprecated".to_string()],
);
let response = HttpResponse::new(200, headers, json!({}));
assert!(response.is_deprecated());Trait Implementations§
Source§impl Clone for HttpResponse
impl Clone for HttpResponse
Source§fn clone(&self) -> HttpResponse
fn clone(&self) -> HttpResponse
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more