pub struct Http { /* private fields */ }Expand description
Builder for executing an HTTP request.
Supports method, URL, headers, body (JSON or text), and timeout.
The response body is captured as a string, with optional typed
JSON deserialization via HttpOutput::json.
Unlike Shell, Http does not
fail on non-2xx status codes - use HttpOutput::is_success to check.
Only transport-level errors (DNS, timeout, connection refused) produce
an OperationError::Http.
§Examples
use std::time::Duration;
use ironflow_core::operations::http::Http;
let output = Http::post("https://httpbin.org/post")
.header("Authorization", "Bearer token123")
.json(serde_json::json!({"key": "value"}))
.timeout(Duration::from_secs(30))
.await?;
println!("status: {}, body: {}", output.status(), output.body());Implementations§
Source§impl Http
impl Http
Sourcepub fn get(url: &str) -> Self
pub fn get(url: &str) -> Self
Create a GET request builder.
§Examples
use ironflow_core::operations::http::Http;
let output = Http::get("https://httpbin.org/get").await?;Sourcepub fn header(self, key: &str, value: &str) -> Self
pub fn header(self, key: &str, value: &str) -> Self
Add a header to the request.
Can be called multiple times to set several headers.
Sourcepub fn json(self, value: Value) -> Self
pub fn json(self, value: Value) -> Self
Set a JSON body.
Content-Type: application/json is added automatically by reqwest.
Takes ownership of the Value to avoid cloning.
Sourcepub fn timeout(self, timeout: Duration) -> Self
pub fn timeout(self, timeout: Duration) -> Self
Override the timeout for the request.
If the request does not complete within this duration, an
OperationError::Http is returned. Defaults to 30 seconds.
Sourcepub fn max_response_size(self, bytes: usize) -> Self
pub fn max_response_size(self, bytes: usize) -> Self
Set the maximum allowed response body size in bytes.
If the response body exceeds this limit, an OperationError::Http is
returned. Defaults to 10 MiB.
Sourcepub fn retry(self, max_retries: u32) -> Self
pub fn retry(self, max_retries: u32) -> Self
Retry the request up to max_retries times on transient failures.
Uses default exponential backoff settings (200ms initial, 2x multiplier,
30s cap). For custom backoff parameters, use retry_policy.
Only transient errors are retried: transport errors (DNS, timeout, connection refused) and responses with status 5xx or 429. Client errors (4xx except 429) and SSRF blocks are never retried.
§Panics
Panics if max_retries is 0.
§Examples
use ironflow_core::operations::http::Http;
let output = Http::get("https://api.example.com/data")
.retry(3)
.await?;Sourcepub fn retry_policy(self, policy: RetryPolicy) -> Self
pub fn retry_policy(self, policy: RetryPolicy) -> Self
Set a custom RetryPolicy for this request.
Allows full control over backoff duration, multiplier, and max delay.
See RetryPolicy for details.
§Examples
use std::time::Duration;
use ironflow_core::operations::http::Http;
use ironflow_core::retry::RetryPolicy;
let output = Http::get("https://api.example.com/data")
.retry_policy(
RetryPolicy::new(5)
.backoff(Duration::from_millis(500))
.max_backoff(Duration::from_secs(60))
.multiplier(3.0)
)
.await?;Sourcepub fn dry_run(self, enabled: bool) -> Self
pub fn dry_run(self, enabled: bool) -> Self
Enable or disable dry-run mode for this specific operation.
When dry-run is active, the request is logged but not sent.
A synthetic HttpOutput is returned with status 200, empty body,
and 0ms duration.
If not set, falls back to the global dry-run setting
(see set_dry_run).
Sourcepub async fn run(self) -> Result<HttpOutput, OperationError>
pub async fn run(self) -> Result<HttpOutput, OperationError>
Execute the HTTP request.
If a retry_policy is configured, transient
failures (transport errors, 5xx, 429) are retried with exponential
backoff. Non-retryable errors and successful responses are returned
immediately.
§Errors
Returns OperationError::Http if the request fails at the transport
layer (network error, DNS failure, timeout) or if the response body
cannot be read. Non-2xx status codes are not treated as errors.