pub async fn serve(
addr: impl ToSocketAddrs,
dispatcher: impl Dispatcher,
) -> Result<(), Error>Expand description
Starts an HTTP server that dispatches requests using the given dispatcher.
Binds a TCP listener on addr, accepts connections, and serves each one
using a hyper auto-connection builder. This eliminates the ~25 lines of
boilerplate that every A2A agent otherwise needs.
The server runs until the listener encounters an I/O error. Each connection is served in a separate Tokio task.
§Errors
Returns std::io::Error if the TCP listener fails to bind.
§Example
use std::sync::Arc;
use a2a_protocol_server::serve::serve;
use a2a_protocol_server::dispatch::JsonRpcDispatcher;
use a2a_protocol_server::RequestHandlerBuilder;
let handler = Arc::new(
RequestHandlerBuilder::new(MyExecutor)
.build()
.expect("build handler"),
);
let dispatcher = JsonRpcDispatcher::new(handler);
serve("127.0.0.1:3000", dispatcher).await?;