Package org.a2aproject.sdk.client.http
@NullMarked
package org.a2aproject.sdk.client.http
HTTP client utilities for A2A protocol communication.
This package provides a pluggable HTTP client abstraction for making HTTP requests to A2A agents, including support for fetching agent cards, synchronous requests, and Server-Sent Events (SSE) streaming.
Core Components
A2AHttpClient- Main HTTP client interface with builder patternA2AHttpClientFactory- Factory for creating client instances via ServiceLoaderA2ACardResolver- Utility for fetching agent cards from standard endpointsA2AHttpResponse- Response wrapper with status and body
Provider System
The module uses a ServiceLoader-based provider system allowing different HTTP client implementations to be plugged in:
JdkA2AHttpClient- Default implementation using JDK 11+ HttpClient (priority 0)- VertxA2AHttpClient - Vertx-based implementation when available (priority 100)
Usage Example
// Fetch an agent card
A2ACardResolver resolver = A2ACardResolver.builder().baseUrl("http://localhost:9999").build();
AgentCard card = resolver.getAgentCard();
// Make HTTP requests
A2AHttpClient client = A2AHttpClientFactory.create();
A2AHttpResponse response = client.createGet()
.url("http://localhost:9999/api/endpoint")
.addHeader("Authorization", "Bearer token")
.get();
// Server-Sent Events (SSE) streaming
client.createPost()
.url("http://localhost:9999/message:stream")
.body(jsonBody)
.postAsyncSSE(
message -> System.out.println("Received: " + message),
error -> System.err.println("Error: " + error),
() -> System.out.println("Stream complete")
);
Agent Card Resolution
Agent cards are fetched from the standard /.well-known/agent-card.json endpoint
by default, with support for tenant-specific paths and custom authentication headers.
- See Also:
-
ClassDescriptionUtility for fetching agent cards from A2A agents.Builder for creating A2ACardResolver instances with a fluent API.HTTP client interface for making HTTP requests to A2A agents.A2AHttpClient.Builder<T extends A2AHttpClient.Builder<T>>Base builder interface for HTTP requests.Builder for HTTP DELETE requests.Builder for HTTP GET requests.Builder for HTTP POST requests.Factory for creating
A2AHttpClientinstances using the ServiceLoader mechanism.Service provider interface for creatingA2AHttpClientinstances.Read-only abstraction over HTTP response headers.HTTP response wrapper containing status code and response body.Android-specific implementation ofA2AHttpClientusingHttpURLConnection.Service provider forAndroidA2AHttpClient.Default HTTP client implementation using JDK 11+HttpClient.Service provider forJdkA2AHttpClient.Represents a parsed Server-Sent Event (SSE).Streaming parser for Server-Sent Events (SSE).Vert.x WebClient-based implementation ofA2AHttpClient.Service provider forVertxA2AHttpClient.