pub struct RestClient { /* private fields */ }Expand description
A generic RestClient which conforms to Lexe’s API.
Implementations§
Source§impl RestClient
impl RestClient
Sourcepub fn new(
from: impl Into<Cow<'static, str>>,
to: &'static str,
tls_config: ClientConfig,
) -> Self
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.
Sourcepub fn new_insecure(
from: impl Into<Cow<'static, str>>,
to: &'static str,
) -> Self
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.
Sourcepub fn client_builder(from: impl AsRef<str>) -> ClientBuilder
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.
Sourcepub fn from_inner(
client: Client,
from: impl Into<Cow<'static, str>>,
to: &'static str,
) -> Self
pub fn from_inner( client: Client, from: impl Into<Cow<'static, str>>, to: &'static str, ) -> Self
Construct a RestClient from a reqwest::Client.
pub fn user_agent(&self) -> &Cow<'static, str>
pub fn get<U, T>(&self, url: U, data: &T) -> RequestBuilder
pub fn post<U, T>(&self, url: U, data: &T) -> RequestBuilder
pub fn put<U, T>(&self, url: U, data: &T) -> RequestBuilder
pub fn delete<U, T>(&self, url: U, data: &T) -> RequestBuilder
Sourcepub fn serialize_ldk_writeable<U, W>(
&self,
method: Method,
url: U,
data: &W,
) -> RequestBuilder
pub fn serialize_ldk_writeable<U, W>( &self, method: Method, url: U, data: &W, ) -> RequestBuilder
Serializes a LDK Writeable object into the request body.
Sourcepub fn builder(&self, method: Method, url: impl IntoUrl) -> RequestBuilder
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.
Sourcepub async fn send<T: DeserializeOwned, E: ApiError>(
&self,
request_builder: RequestBuilder,
) -> Result<T, E>
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.
Sourcepub async fn send_no_deserialize<E: ApiError>(
&self,
request_builder: RequestBuilder,
) -> Result<Bytes, E>
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.
Sourcepub async fn send_and_stream_response<E: ApiError>(
&self,
request_builder: RequestBuilder,
) -> Result<StreamBody, E>
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.
Sourcepub async fn send_with_retries<T: DeserializeOwned, E: ApiError>(
&self,
request_builder: RequestBuilder,
retries: usize,
stop_codes: &[ErrorCode],
) -> Result<T, E>
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
impl Clone for RestClient
Source§fn clone(&self) -> RestClient
fn clone(&self) -> RestClient
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more