pub struct Client<L = RpcLink> { /* private fields */ }Expand description
oRPC client for calling remote procedures.
Wraps a Link implementation and provides typed convenience methods
for queries, mutations, and subscriptions.
§Example
ⓘ
use orpc_client::Client;
let client = Client::new("http://localhost:3000/rpc");
// Query / Mutation
let planet: Planet = client.call("planet.find", &FindInput { name: "Earth".into() }).await?;
// Subscription (SSE stream)
use futures_util::StreamExt;
let mut stream = client.subscribe::<Planet>("planet.stream", &()).await?;
while let Some(result) = stream.next().await {
let planet = result?;
println!("New planet: {planet:?}");
}Implementations§
Source§impl<L: Link> Client<L>
impl<L: Link> Client<L>
Sourcepub async fn call<I, O>(&self, path: &str, input: &I) -> Result<O, ClientError>where
I: Serialize,
O: DeserializeOwned,
pub async fn call<I, O>(&self, path: &str, input: &I) -> Result<O, ClientError>where
I: Serialize,
O: DeserializeOwned,
Call a procedure and deserialize the response.
Works for both queries (read) and mutations (write).
Sourcepub async fn subscribe<O>(
&self,
path: &str,
input: &impl Serialize,
) -> Result<impl Stream<Item = Result<O, ClientError>>, ClientError>where
O: DeserializeOwned + 'static,
pub async fn subscribe<O>(
&self,
path: &str,
input: &impl Serialize,
) -> Result<impl Stream<Item = Result<O, ClientError>>, ClientError>where
O: DeserializeOwned + 'static,
Subscribe to a streaming procedure.
Returns a stream of deserialized values. The stream ends when the
server sends a done event or an error event.
Sourcepub async fn subscribe_from<O>(
&self,
path: &str,
input: &impl Serialize,
last_event_id: Option<u64>,
) -> Result<impl Stream<Item = Result<O, ClientError>>, ClientError>where
O: DeserializeOwned + 'static,
pub async fn subscribe_from<O>(
&self,
path: &str,
input: &impl Serialize,
last_event_id: Option<u64>,
) -> Result<impl Stream<Item = Result<O, ClientError>>, ClientError>where
O: DeserializeOwned + 'static,
Subscribe with a specific last_event_id for SSE reconnection.
The server will resume from events after last_event_id.
Auto Trait Implementations§
impl<L> Freeze for Client<L>where
L: Freeze,
impl<L> RefUnwindSafe for Client<L>where
L: RefUnwindSafe,
impl<L> Send for Client<L>where
L: Send,
impl<L> Sync for Client<L>where
L: Sync,
impl<L> Unpin for Client<L>where
L: Unpin,
impl<L> UnsafeUnpin for Client<L>where
L: UnsafeUnpin,
impl<L> UnwindSafe for Client<L>where
L: UnwindSafe,
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
Mutably borrows from an owned value. Read more