BloomRpcRouter class
Server-side RPC router and registry mapping BloomRpcContract endpoints to BloomRpcHandler callbacks.
Provides a unified registry for declaring server implementations of shared RPC contracts, matching incoming requests, extracting typed parameters, and invoking handlers.
Server Integration Example
// 1. Define shared contract
const getTask = BloomRpcContract<void, Task>.get(
'/tasks/:id',
decodeOutput: Task.fromJson,
);
// 2. Register server implementation
final rpcRouter = BloomRpcRouter();
rpcRouter.bind(getTask, (ctx, _) async {
final taskId = ctx.pathParams['id']!;
return taskRepository.findById(taskId);
});
// 3. Mount onto server / bloom_server adapter
// In a bloom_server application:
for (final binding in rpcRouter.bindings) {
serverRouter.add(binding.contract.method.value, binding.contract.pathTemplate, (req) async {
final rpcReq = BloomRpcServerRequest(
method: req.method,
path: req.path,
headers: req.headers,
queryParams: req.queryParams,
body: req.bodyJson,
rawRequest: req,
);
final res = await rpcRouter.handle(rpcReq);
return BloomResponse.json(res.body, statusCode: res.statusCode);
});
}
Constructors
Properties
-
bindings
→ List<
BloomRpcBinding> -
An unmodifiable list of all registered RPC endpoint bindings.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
bind<
TInput, TOutput> (BloomRpcContract< TInput, TOutput> contract, BloomRpcHandler<TInput, TOutput> handler) → void -
Registers a server handler for
contract. -
handle(
BloomRpcServerRequest request) → Future< BloomRpcServerResponse> -
Dispatches an incoming
requestto the matching registered contract binding. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited