Skip to main content

Http

Struct Http 

Source
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

Source

pub fn new(method: Method, url: &str) -> Self

Create a request builder with an arbitrary HTTP method.

§Panics

Panics if url is empty.

Source

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?;
Source

pub fn post(url: &str) -> Self

Create a POST request builder.

Source

pub fn put(url: &str) -> Self

Create a PUT request builder.

Source

pub fn patch(url: &str) -> Self

Create a PATCH request builder.

Source

pub fn delete(url: &str) -> Self

Create a DELETE request builder.

Source

pub fn header(self, key: &str, value: &str) -> Self

Add a header to the request.

Can be called multiple times to set several headers.

Source

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.

Source

pub fn text(self, body: &str) -> Self

Set a plain text body.

Source

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.

Source

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.

Source

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?;
Source

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?;
Source

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).

Source

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.

Trait Implementations§

Source§

impl IntoFuture for Http

Source§

type Output = Result<HttpOutput, OperationError>

The output that the future will produce on completion.
Source§

type IntoFuture = Pin<Box<dyn Future<Output = <Http as IntoFuture>::Output> + Send>>

Which kind of future are we turning this into?
Source§

fn into_future(self) -> Self::IntoFuture

Creates a future from a value. Read more

Auto Trait Implementations§

§

impl Freeze for Http

§

impl RefUnwindSafe for Http

§

impl Send for Http

§

impl Sync for Http

§

impl Unpin for Http

§

impl UnsafeUnpin for Http

§

impl UnwindSafe for Http

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more