pub struct HttpRequest {
pub http_method: HttpMethod,
pub path: String,
pub body: Option<Value>,
pub body_type: Option<DataType>,
pub query: Option<HashMap<String, String>>,
pub extra_headers: Option<HashMap<String, String>>,
pub tries: u32,
}Expand description
An HTTP request to be sent to the Shopify API.
Use HttpRequest::builder to construct requests with the builder pattern.
§Example
use shopify_sdk::clients::{HttpRequest, HttpMethod, DataType};
use serde_json::json;
// GET request
let get_request = HttpRequest::builder(HttpMethod::Get, "products.json")
.build()
.unwrap();
// POST request with JSON body
let post_request = HttpRequest::builder(HttpMethod::Post, "products.json")
.body(json!({"product": {"title": "New Product"}}))
.body_type(DataType::Json)
.build()
.unwrap();Fields§
§http_method: HttpMethodThe HTTP method for this request.
path: StringThe path (relative to base path) for this request.
body: Option<Value>The request body, if any.
body_type: Option<DataType>The content type of the body.
query: Option<HashMap<String, String>>Query parameters to append to the URL.
extra_headers: Option<HashMap<String, String>>Additional headers to include in the request.
tries: u32Number of times to attempt the request (default: 1).
Implementations§
Source§impl HttpRequest
impl HttpRequest
Sourcepub fn builder(
method: HttpMethod,
path: impl Into<String>,
) -> HttpRequestBuilder
pub fn builder( method: HttpMethod, path: impl Into<String>, ) -> HttpRequestBuilder
Creates a new builder for constructing an HttpRequest.
§Arguments
method- The HTTP method for the requestpath- The path (relative to base path) for the request
§Example
use shopify_sdk::clients::{HttpRequest, HttpMethod};
let request = HttpRequest::builder(HttpMethod::Get, "products.json")
.tries(3)
.build()
.unwrap();Sourcepub fn verify(&self) -> Result<(), InvalidHttpRequestError>
pub fn verify(&self) -> Result<(), InvalidHttpRequestError>
Validates the request, ensuring it meets all requirements.
§Errors
Returns InvalidHttpRequestError if:
bodyisSomebutbody_typeisNonehttp_methodisPostorPutbutbodyisNone
Trait Implementations§
Source§impl Clone for HttpRequest
impl Clone for HttpRequest
Source§fn clone(&self) -> HttpRequest
fn clone(&self) -> HttpRequest
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for HttpRequest
impl RefUnwindSafe for HttpRequest
impl Send for HttpRequest
impl Sync for HttpRequest
impl Unpin for HttpRequest
impl UnwindSafe for HttpRequest
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more