java.lang.Object
io.jooby.trpc.TrpcModule
- All Implemented Interfaces:
io.jooby.Extension
Jooby extension that enables tRPC support for the application.
This module is responsible for bootstrapping the required tRPC infrastructure, specifically the specialized error handling and the parameter parsing mechanisms needed to handle tRPC network payloads.
Prerequisites:
Because tRPC relies heavily on JSON serialization, a JSON module (such as
JacksonModule, or AvajeJsonbModule) must be installed before installing this
module. The JSON module automatically registers the underlying TrpcParser that this
extension requires.
Usage:
{
// 1. Install a JSON engine (Prerequisite)
install(new Jackson3Module())
// 2. JSON implementation of protocol
install(new TrpcJackson3Module());
// 3. Install the tRPC extension
install(new TrpcModule(MovieServiceTrpc_()));
}
-
Constructor Summary
ConstructorsConstructorDescriptionTrpcModule(TrpcService service, TrpcService... services) Constructs a newTrpcModulewith the default base path:trpcand the provided services.TrpcModule(String path, TrpcService service, TrpcService... services) Creates a new instance ofTrpcModulewith the specified base path and tRPC services. -
Method Summary
Modifier and TypeMethodDescriptionvoidinstall(io.jooby.Jooby app) Installs the tRPC extension into the Jooby application.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.jooby.Extension
lateinit
-
Constructor Details
-
TrpcModule
Creates a new instance ofTrpcModulewith the specified base path and tRPC services.- Parameters:
path- The base path for all tRPC routes. This is the root URL prefix where all tRPC services will be registered. Must not benull.service- The primary tRPC service to register. Must not benull.services- Additional tRPC services to register (if any). Optional and may be omitted.
-
TrpcModule
Constructs a newTrpcModulewith the default base path:trpcand the provided services.- Parameters:
service- The primary tRPC service to register. Must not benull.services- Additional tRPC services to register (if any). Optional and may be omitted.
-
-
Method Details
-
install
Installs the tRPC extension into the Jooby application.During installation, this method performs the following setup:
- Validates that a
TrpcParseris available in the service registry. - Initializes the registry map for custom
ClasstoTrpcErrorCodemappings, allowing developers to map domain exceptions to specific tRPC errors. - Registers the
TrpcErrorHandlerglobally to intercept and correctly format exceptions thrown from/trpc/*endpoints.
- Specified by:
installin interfaceio.jooby.Extension- Parameters:
app- The current Jooby application.- Throws:
Exception- If a required service (such as theTrpcParser) is missing from the registry.
- Validates that a
-