pub struct WebA2AClient {
pub http: HttpClient,
pub ws: Option<Arc<WebSocketClient>>,
}Expand description
Web-friendly A2A client that wraps both HTTP and WebSocket clients.
This is the main entry point for interacting with A2A agents from web applications. It provides a unified interface for both HTTP and WebSocket transports, with automatic fallback and retry logic.
§Examples
§HTTP-only client
use a2a_client::WebA2AClient;
let client = WebA2AClient::new_http("http://localhost:8080".to_string());§Client with WebSocket support
use a2a_client::WebA2AClient;
let client = WebA2AClient::new_with_websocket(
"http://localhost:8080".to_string(),
"ws://localhost:8080/ws".to_string()
);§Auto-detecting transports
use a2a_client::WebA2AClient;
let client = WebA2AClient::auto_connect("http://localhost:8080").await?;Fields§
§http: HttpClientHTTP client for JSON-RPC requests
ws: Option<Arc<WebSocketClient>>Optional WebSocket client for streaming updates
Implementations§
Source§impl WebA2AClient
impl WebA2AClient
Sourcepub fn builder() -> WebA2AClientBuilder
pub fn builder() -> WebA2AClientBuilder
Create a builder for configuring the client.
§Examples
use a2a_client::WebA2AClient;
let client = WebA2AClient::builder()
.http_url("http://localhost:8080")
.build();Sourcepub fn new_with_websocket(http_url: String, ws_url: String) -> Self
pub fn new_with_websocket(http_url: String, ws_url: String) -> Self
Create a new client with both HTTP and WebSocket transports.
§Arguments
http_url- HTTP base URL (e.g.,http://localhost:8080)ws_url- WebSocket URL (e.g.,ws://localhost:8080/ws)
§Examples
use a2a_client::WebA2AClient;
let client = WebA2AClient::new_with_websocket(
"http://localhost:8080".to_string(),
"ws://localhost:8080/ws".to_string()
);Sourcepub async fn auto_connect(base_url: &str) -> Result<Self>
pub async fn auto_connect(base_url: &str) -> Result<Self>
Auto-connect to an agent, attempting to detect available transports.
Currently defaults to HTTP-only. In the future, this will probe for WebSocket support by checking the agent card.
§Arguments
base_url- Base URL of the A2A agent
§Examples
use a2a_client::WebA2AClient;
let client = WebA2AClient::auto_connect("http://localhost:8080").await?;Sourcepub fn has_websocket(&self) -> bool
pub fn has_websocket(&self) -> bool
Check if WebSocket transport is available.
§Examples
use a2a_client::WebA2AClient;
let client = WebA2AClient::new_http("http://localhost:8080".to_string());
assert!(!client.has_websocket());
let client = WebA2AClient::new_with_websocket(
"http://localhost:8080".to_string(),
"ws://localhost:8080/ws".to_string()
);
assert!(client.has_websocket());Sourcepub fn websocket(&self) -> Option<&Arc<WebSocketClient>>
pub fn websocket(&self) -> Option<&Arc<WebSocketClient>>
Get a reference to the WebSocket client if available.
§Examples
use a2a_client::WebA2AClient;
let client = WebA2AClient::new_with_websocket(
"http://localhost:8080".to_string(),
"ws://localhost:8080/ws".to_string()
);
if let Some(ws_client) = client.websocket() {
// Use WebSocket client
}Auto Trait Implementations§
impl Freeze for WebA2AClient
impl !RefUnwindSafe for WebA2AClient
impl Send for WebA2AClient
impl Sync for WebA2AClient
impl Unpin for WebA2AClient
impl UnsafeUnpin for WebA2AClient
impl !UnwindSafe for WebA2AClient
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