pub struct HttpRequest {
pub id: RequestId,
pub method: Method,
pub url: String,
pub headers: HashMap<String, String>,
pub body: Option<Vec<u8>>,
pub timeout: Duration,
pub max_retries: u32,
pub priority: i32,
pub tag: Option<String>,
pub cache_policy: CachePolicy,
}Expand description
An HTTP request to be issued by the client.
Fields§
§id: RequestIdUnique id, used to match events to requests.
method: MethodHTTP method.
url: StringFull URL including scheme, for example https://example.com/scores.
headers: HashMap<String, String>Request headers.
body: Option<Vec<u8>>Request body, if any.
timeout: DurationTime allowed for each attempt (default 10 s).
max_retries: u32Retries after a connection error, timeout or 5xx response (default 3).
priority: i32Priority: higher = processed first. Default 0.
tag: Option<String>Tag for grouping/cancellation.
cache_policy: CachePolicyCache behavior.
Implementations§
Source§impl HttpRequest
impl HttpRequest
Sourcepub fn post_json(url: impl Into<String>, json: impl Into<String>) -> Self
pub fn post_json(url: impl Into<String>, json: impl Into<String>) -> Self
A POST request with a JSON body and Content-Type: application/json.
Sourcepub fn new(method: Method, url: impl Into<String>) -> Self
pub fn new(method: Method, url: impl Into<String>) -> Self
A request with a fresh id, 10 s timeout, 3 retries and UseCache.
Sourcepub fn with_header(self, key: impl Into<String>, val: impl Into<String>) -> Self
pub fn with_header(self, key: impl Into<String>, val: impl Into<String>) -> Self
Add or replace a header.
Sourcepub fn with_timeout(self, t: Duration) -> Self
pub fn with_timeout(self, t: Duration) -> Self
Set the per-attempt timeout.
Sourcepub fn with_retries(self, n: u32) -> Self
pub fn with_retries(self, n: u32) -> Self
Set the number of retries.
Sourcepub fn with_priority(self, p: i32) -> Self
pub fn with_priority(self, p: i32) -> Self
Set the priority; higher is sent first.
Sourcepub fn with_tag(self, t: impl Into<String>) -> Self
pub fn with_tag(self, t: impl Into<String>) -> Self
Set a tag that HttpClient::cancel_by_tag can match.
Sourcepub fn with_cache(self, p: CachePolicy) -> Self
pub fn with_cache(self, p: CachePolicy) -> Self
Set the cache policy.
Sourcepub fn bearer_auth(self, token: impl Into<String>) -> Self
pub fn bearer_auth(self, token: impl Into<String>) -> Self
Add Authorization: Bearer <token>.
Trait Implementations§
Source§impl Clone for HttpRequest
impl Clone for HttpRequest
Auto Trait Implementations§
impl Freeze for HttpRequest
impl RefUnwindSafe for HttpRequest
impl Send for HttpRequest
impl Sync for HttpRequest
impl Unpin for HttpRequest
impl UnsafeUnpin 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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more