RPCRouter
Stores and provides handlers for RPCs.
struct RPCRouter<Transport> where Transport : ServerTransport
The router stores a handler for each RPC it knows about. Each handler encapsulate the business logic for the RPC which is typically implemented by service owners. To register a handler you can call registerHandler(forMethod:deserializer:serializer:handler:)
. You can check whether the router has a handler for a method with hasHandler(forMethod:)
or get a list of all methods with handlers registered by calling methods
. You can also remove the handler for a given method by calling removeHandler(forMethod:)
. You can also register any interceptors that you want applied to registered handlers via the registerInterceptors(pipeline:)
method.
In most cases you won’t need to interact with the router directly. Instead you should register your services with init(transport:services:interceptors:)
which will in turn register each method with the router.
You may wish to not serve all methods from your service in which case you can either:
Remove individual methods by calling
removeHandler(forMethod:)
, orImplement
registerMethods(with:)
to register only the methods you want to be served.