Skip to main content

RestClient

Struct RestClient 

Source
pub struct RestClient { /* private fields */ }
Expand description

A generic RestClient which conforms to Lexe’s API.

Implementations§

Source§

impl RestClient

Source

pub fn new( from: impl Into<Cow<'static, str>>, to: &'static str, tls_config: ClientConfig, ) -> Self

Builds a new RestClient with the given TLS config and safe defaults.

The from and to fields should succinctly specify the client and server components of the API trait that this RestClient is used for, e.g. from=“app”, to=“node-run” or from=“node”, to=“backend”. The RestClient will log both fields so that requests from this client can be differentiated from those made by other clients in the same process, and propagate the from field to the server via the user agent header so that servers can identify requesting clients.

Source

pub fn new_insecure( from: impl Into<Cow<'static, str>>, to: &'static str, ) -> Self

RestClient::new but without TLS. This should only be used for non-security-critical endpoints.

Source

pub fn client_builder(from: impl AsRef<str>) -> ClientBuilder

Get a reqwest::ClientBuilder with some defaults set. NOTE that for safety, https_only is set to true, but you can override it if needed.

Source

pub fn from_inner( client: Client, from: impl Into<Cow<'static, str>>, to: &'static str, ) -> Self

Construct a RestClient from a reqwest::Client.

Source

pub fn user_agent(&self) -> &Cow<'static, str>

Source

pub fn get<U, T>(&self, url: U, data: &T) -> RequestBuilder
where U: IntoUrl, T: Serialize + ?Sized,

Source

pub fn post<U, T>(&self, url: U, data: &T) -> RequestBuilder
where U: IntoUrl, T: Serialize + ?Sized,

Source

pub fn put<U, T>(&self, url: U, data: &T) -> RequestBuilder
where U: IntoUrl, T: Serialize + ?Sized,

Source

pub fn delete<U, T>(&self, url: U, data: &T) -> RequestBuilder
where U: IntoUrl, T: Serialize + ?Sized,

Source

pub fn serialize_ldk_writeable<U, W>( &self, method: Method, url: U, data: &W, ) -> RequestBuilder
where U: IntoUrl, W: Writeable,

Serializes a LDK Writeable object into the request body.

Source

pub fn builder(&self, method: Method, url: impl IntoUrl) -> RequestBuilder

A clean slate reqwest::RequestBuilder for non-standard requests. Otherwise prefer to use the ready-made get, post, …, etc helpers.

Source

pub async fn send<T: DeserializeOwned, E: ApiError>( &self, request_builder: RequestBuilder, ) -> Result<T, E>

Sends the built HTTP request. Tries to JSON deserialize the response body to T.

Source

pub async fn send_no_deserialize<E: ApiError>( &self, request_builder: RequestBuilder, ) -> Result<Bytes, E>

Sends the HTTP request, but doesn’t JSON-deserialize the response.

Source

pub async fn send_and_stream_response<E: ApiError>( &self, request_builder: RequestBuilder, ) -> Result<StreamBody, E>

Sends the HTTP request, but returns a StreamBody that yields Bytes chunks as they arrive.

Source

pub async fn send_with_retries<T: DeserializeOwned, E: ApiError>( &self, request_builder: RequestBuilder, retries: usize, stop_codes: &[ErrorCode], ) -> Result<T, E>

Sends the built HTTP request, retrying up to retries times. Tries to JSON deserialize the response body to T.

If one of the request attempts yields an error code in stop_codes, we will immediately stop retrying and return that error.

See also: RestClient::send

Trait Implementations§

Source§

impl Clone for RestClient

Source§

fn clone(&self) -> RestClient

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

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<F, T, U> Apply<F, U> for T
where F: FnOnce(T) -> U,

Source§

fn apply(self, f: F) -> U

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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