pub trait SendRequest {
// Required methods
fn set_request(request: &Request) -> Self;
fn send<T: ApiRequest>(
&self,
request: &T,
) -> impl Future<Output = Result<Response, Error>>;
fn build_request_headers<T: ApiRequest>(
&self,
now_date: &str,
request_builder: RequestBuilder,
request: &T,
) -> Result<RequestBuilder, Error>;
fn build_request_headers_authorization<T: ApiRequest>(
&self,
now_date: &str,
request: &T,
request_builder: RequestBuilder,
) -> Result<RequestBuilder, Error>;
fn build_request<T: ApiRequest>(
&self,
request: &T,
) -> Result<RequestBuilder, Error>;
fn format_request_hashmap<T: ApiRequest>(
&self,
request: &T,
) -> HashMap<String, String>;
fn get_x_date(&self) -> String;
}Expand description
Trait for handling the creation, signing, and sending of API requests. Provides methods for building request headers, signing them, and sending requests.
Required Methods§
Sourcefn set_request(request: &Request) -> Self
fn set_request(request: &Request) -> Self
Sets the request for the struct implementing this trait.
This method takes a reference to a request::Request and returns an instance
of the implementing type with the request set.
§Arguments
request: A reference to arequest::Requestthat will be set.
§Returns
Returns an instance of the implementing struct with the request set.
Sourcefn send<T: ApiRequest>(
&self,
request: &T,
) -> impl Future<Output = Result<Response, Error>>
fn send<T: ApiRequest>( &self, request: &T, ) -> impl Future<Output = Result<Response, Error>>
Sends the request to the server and returns the response.
This method is responsible for sending the request to the server asynchronously and returning the server’s response. It handles the serialization of the request, making the API call, and processing the response.
§Arguments
request: A reference to a type implementingApiRequest, which defines the structure of the request.
§Returns
A future that resolves to a result containing the server’s response or an error.
Sourcefn build_request_headers<T: ApiRequest>(
&self,
now_date: &str,
request_builder: RequestBuilder,
request: &T,
) -> Result<RequestBuilder, Error>
fn build_request_headers<T: ApiRequest>( &self, now_date: &str, request_builder: RequestBuilder, request: &T, ) -> Result<RequestBuilder, Error>
Builds the request headers, including all necessary metadata.
This method is responsible for building the headers for the HTTP request. The headers are added to the request builder, which will later be used to make the API call.
§Arguments
now_date: The current date in the required format, typically used for signing headers.request_builder: ARequestBuilderinstance that will be populated with the headers.request: A reference to a type implementingApiRequestto extract specific header data.
§Returns
Returns a Result containing either the populated RequestBuilder with headers or an error.
Builds the request headers and adds the authorization header.
This method extends build_request_headers by adding an authorization header to
the request. The authorization header is typically generated using an HMAC or similar
signing method to ensure secure communication.
§Arguments
now_date: The current UTC date in a specific format, used for signing the authorization.request: A reference to a type implementingApiRequest, which provides data for the request.request_builder: The request builder to which the authorization header will be added.
§Returns
Returns a Result containing the modified RequestBuilder with the authorization header
or an error.
Sourcefn build_request<T: ApiRequest>(
&self,
request: &T,
) -> Result<RequestBuilder, Error>
fn build_request<T: ApiRequest>( &self, request: &T, ) -> Result<RequestBuilder, Error>
Builds the request object itself.
This method is responsible for constructing the base HTTP request, including the URL, HTTP method, and other essential components required to perform the request.
§Arguments
request: A reference to a type implementingApiRequestto obtain the necessary data for the request, such as the URL and HTTP method.
§Returns
Returns a Result containing the constructed RequestBuilder or an error.
Sourcefn format_request_hashmap<T: ApiRequest>(
&self,
request: &T,
) -> HashMap<String, String>
fn format_request_hashmap<T: ApiRequest>( &self, request: &T, ) -> HashMap<String, String>
Converts the request parameters into a HashMap.
This method formats the parameters for the request into a HashMap, where the keys
are the names of the parameters and the values are their respective values.
§Arguments
request: A reference to a type implementingApiRequest, which contains the parameters to be formatted.
§Returns
A HashMap<String, String> containing the formatted request parameters.
Sourcefn get_x_date(&self) -> String
fn get_x_date(&self) -> String
Retrieves the current UTC date formatted as a string.
This method generates the current UTC date in a specific format, which is commonly used for API signature generation or as part of headers for request authentication.
§Returns
A string representing the current UTC date in the required format (e.g., 20250205T120000Z).
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.
Implementors§
impl SendRequest for Send
@description: Implementation of SendRequest trait for Send struct. @author: Jerry.Yang @date: 2024-11-08 10:46:32 @return {*}