#[non_exhaustive]pub struct PreparedRequest {
pub method: Method,
pub url: String,
pub query_pairs: Vec<(String, String)>,
pub headers: Vec<(String, String)>,
pub body: Option<Value>,
pub auth: ResolvedAuth,
}Expand description
A fully resolved HTTP request ready to be sent or inspected.
Created by PreparedRequest::from_operation, this struct holds all the
data needed to execute an HTTP request. Consumers can inspect the fields
for dry-run display, verbose logging, or request modification before
calling send.
§Example
let prepared = PreparedRequest::from_operation(
"https://api.example.com",
&Auth::Bearer("token"),
op,
matches,
)?;
// Inspect before sending (dry-run / verbose)
eprintln!("{} {}", prepared.method, prepared.url);
let resp = prepared.send(&Client::new())?;
let value = resp.into_json()?;Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.method: MethodHTTP method (GET, POST, etc.).
url: StringFully resolved URL with path parameters substituted.
query_pairs: Vec<(String, String)>Query parameters from the API operation.
Auth query parameters (see ResolvedAuth::Query) are kept in the
auth field and applied separately during
send.
headers: Vec<(String, String)>Headers from the API operation.
Auth headers are kept in the auth field.
body: Option<Value>JSON request body, if any.
auth: ResolvedAuthResolved authentication.
Implementations§
Source§impl PreparedRequest
impl PreparedRequest
Sourcepub fn new(method: Method, url: impl Into<String>) -> Self
pub fn new(method: Method, url: impl Into<String>) -> Self
Create a new prepared request with the given HTTP method and URL.
Use the builder methods (query, header,
body, auth) to set additional fields,
then call send to execute.
§Example
let req = PreparedRequest::new(Method::POST, "https://api.example.com/v2/abc/run")
.auth(ResolvedAuth::Bearer("my-token".into()))
.body(json!({"input": {"prompt": "hello"}}));Sourcepub fn query(self, name: impl Into<String>, value: impl Into<String>) -> Self
pub fn query(self, name: impl Into<String>, value: impl Into<String>) -> Self
Add a query parameter.
Sourcepub fn auth(self, auth: ResolvedAuth) -> Self
pub fn auth(self, auth: ResolvedAuth) -> Self
Set the authentication method.
Sourcepub fn clear_query(self) -> Self
pub fn clear_query(self) -> Self
Remove all query parameters.
Sourcepub fn clear_headers(self) -> Self
pub fn clear_headers(self) -> Self
Remove all headers.
Sourcepub fn from_operation(
base_url: &str,
auth: &Auth<'_>,
op: &ApiOperation,
matches: &ArgMatches,
) -> Result<Self, DispatchError>
pub fn from_operation( base_url: &str, auth: &Auth<'_>, op: &ApiOperation, matches: &ArgMatches, ) -> Result<Self, DispatchError>
Resolve URL, parameters, headers, and authentication from an API operation and clap matches.
The request body is not included — use build_body to resolve
it separately, then chain with .body(). The
convenience function dispatch handles this automatically.
Sourcepub fn send(&self, client: &Client) -> Result<SendResponse, DispatchError>
pub fn send(&self, client: &Client) -> Result<SendResponse, DispatchError>
Send the prepared request and return full response metadata.
Use SendResponse::into_json to check the status and parse the body,
or access SendResponse fields directly for verbose logging.
Trait Implementations§
Source§impl Clone for PreparedRequest
impl Clone for PreparedRequest
Source§fn clone(&self) -> PreparedRequest
fn clone(&self) -> PreparedRequest
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more