pub struct TwirpHttpClient<S: TwirpHttpService> { /* private fields */ }
Expand description
Underlying client used by autogenerated clients to handle networking.
Can be constructed with TwirpHttpClient::new_using_reqwest_012
to use reqwest 0.12
or from a regular tower::Service
using TwirpHttpClient::new_with_base
or TwirpHttpClient::new
if relative URLs are fine.
URL grammar for twirp service is URL ::= Base-URL [ Prefix ] "/" [ Package "." ] Service "/" Method
.
The / [ Package "." ] Service "/" Method
part is auto-generated by the build step
but the Base-URL [ Prefix ]
must be set to do proper call to remote services.
This is the base_url
parameter.
If not filled, request URL is only going to be the auto-generated part.
Implementations§
Source§impl TwirpHttpClient<Reqwest012Service>
impl TwirpHttpClient<Reqwest012Service>
Sourcepub fn new_using_reqwest_012(base_url: impl Into<String>) -> Self
Available on crate feature reqwest-012
only.
pub fn new_using_reqwest_012(base_url: impl Into<String>) -> Self
reqwest-012
only.Builds a new client using reqwest 0.12
.
Note that base_url
must be absolute with a scheme like https://
.
use twurst_client::TwirpHttpClient;
let _client = TwirpHttpClient::new_using_reqwest_012("http://example.com/twirp");
Sourcepub fn new_with_reqwest_012_client(
client: Client,
base_url: impl Into<String>,
) -> Self
Available on crate feature reqwest-012
only.
pub fn new_with_reqwest_012_client( client: Client, base_url: impl Into<String>, ) -> Self
reqwest-012
only.Builds a new client using reqwest 0.12
.
Note that base_url
must be absolute with a scheme like https://
.
use twurst_client::TwirpHttpClient;
let _client =
TwirpHttpClient::new_with_reqwest_012_client(Client::new(), "http://example.com/twirp");
Source§impl<S: TwirpHttpService> TwirpHttpClient<S>
impl<S: TwirpHttpService> TwirpHttpClient<S>
Sourcepub fn new_with_base(service: S, base_url: impl Into<String>) -> Self
pub fn new_with_base(service: S, base_url: impl Into<String>) -> Self
Builds a new client from a tower::Service
and a base URL to the Twirp endpoint.
use http::Response;
use std::convert::Infallible;
use twurst_client::TwirpHttpClient;
use twurst_error::TwirpError;
let _client = TwirpHttpClient::new_with_base(
tower::service_fn(|_request| async {
Ok::<Response<String>, Infallible>(TwirpError::unimplemented("not implemented").into())
}),
"http://example.com/twirp",
);
Sourcepub fn new(service: S) -> Self
pub fn new(service: S) -> Self
New service without base URL. Relative URLs will be used for requests!
use http::Response;
use std::convert::Infallible;
use twurst_client::TwirpHttpClient;
use twurst_error::TwirpError;
let _client = TwirpHttpClient::new(tower::service_fn(|_request| async {
Ok::<Response<String>, Infallible>(TwirpError::unimplemented("not implemented").into())
}));
Sourcepub fn use_json(&mut self)
pub fn use_json(&mut self)
Use JSON for requests and response instead of binary protobuf encoding that is used by default
Sourcepub fn use_binary_protobuf(&mut self)
pub fn use_binary_protobuf(&mut self)
Use binary protobuf encoding for requests and response (the default)
Sourcepub async fn call<I: ReflectMessage, O: ReflectMessage + Default>(
&self,
path: &str,
request: &I,
) -> Result<O, TwirpError>
pub async fn call<I: ReflectMessage, O: ReflectMessage + Default>( &self, path: &str, request: &I, ) -> Result<O, TwirpError>
Send a Twirp request and get a response.
Used internally by the generated code.
Trait Implementations§
Source§impl<S: Clone + TwirpHttpService> Clone for TwirpHttpClient<S>
impl<S: Clone + TwirpHttpService> Clone for TwirpHttpClient<S>
Source§fn clone(&self) -> TwirpHttpClient<S>
fn clone(&self) -> TwirpHttpClient<S>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more