Overview
Concrete REST client transport implementation for A2A communication over standard HTTP REST endpoints with URL-encoded path parameters and SSE streaming.
Description
The RestTransport class implements the ClientTransport SPI using REST/HTTP endpoints. It uses A2AHttpClient for HTTP calls, constructs REST URLs with URLEncoder for path parameters (e.g., `/message:send`, `/tasks/{id}`), and uses JsonFormat for protobuf-JSON conversion. SSE streaming is handled for `subscribeToTask` and `sendMessageStreaming` via SSEEventListener. HTTP status codes are mapped to A2A exceptions via RestErrorMapper.
Usage
- REST-based A2A agents: Use when the agent exposes standard HTTP REST endpoints rather than JSON-RPC
- Standard HTTP tooling: Compatible with standard HTTP proxies, load balancers, and debugging tools
- SSE streaming: Uses Server-Sent Events for streaming task updates
Code Reference
Source Location
- Repository: a2a-java
- File: `client/transport/rest/src/main/java/org/a2aproject/sdk/client/transport/rest/RestTransport.java`
- Lines: L66-518
Signature
public class RestTransport implements ClientTransport {
public RestTransport(AgentCard agentCard);
public RestTransport(@Nullable A2AHttpClient httpClient, AgentCard agentCard,
AgentInterface agentInterface,
@Nullable List<ClientCallInterceptor> interceptors);
// All ClientTransport methods: sendMessage, sendMessageStreaming,
// getTask, cancelTask, listTasks, subscribeToTask, etc.
}
Import
import org.a2aproject.sdk.client.transport.rest.RestTransport;
I/O Contract
Inputs
| Name |
Type |
Required |
Description
|
| agentCard |
AgentCard |
Yes |
Resolved agent card with REST interface
|
| httpClient |
A2AHttpClient |
No |
Custom HTTP client (default if null)
|
| agentInterface |
AgentInterface |
Yes |
Interface with REST base URL
|
| interceptors |
List<ClientCallInterceptor> |
No |
Call interceptors for auth
|
| request |
MessageSendParams |
Yes (sendMessage) |
Message parameters
|
Outputs
| Name |
Type |
Description
|
| sendMessage returns |
EventKind |
Message or Task response
|
| Streaming events |
StreamingEventKind |
Delivered via SSE event consumer
|
| Exceptions |
A2AClientException |
Communication or protocol errors
|
Usage Examples
REST Message Send
import org.a2aproject.sdk.client.transport.rest.RestTransport;
import org.a2aproject.sdk.spec.EventKind;
RestTransport transport = new RestTransport(agentCard);
EventKind result = transport.sendMessage(
A2A.toMessageSendParams("What is the weather?"), null);
Subscribe to Task Updates
transport.subscribeToTask(
new TaskIdParams("task-123"),
event -> System.out.println("Task update: " + event),
error -> System.err.println("Subscribe error: " + error),
null
);
Related Pages
Page Connections
Double-click a node to navigate. Hold to expand connections.