Package io.jooby.trpc

Class TrpcModule

java.lang.Object
io.jooby.trpc.TrpcModule
All Implemented Interfaces:
io.jooby.Extension

public class TrpcModule extends Object implements 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

    Constructors
    Constructor
    Description
    TrpcModule(TrpcService service, TrpcService... services)
    Constructs a new TrpcModule with the default base path: trpc and the provided services.
    TrpcModule(String path, TrpcService service, TrpcService... services)
    Creates a new instance of TrpcModule with the specified base path and tRPC services.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    install(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, wait

    Methods inherited from interface io.jooby.Extension

    lateinit
  • Constructor Details

    • TrpcModule

      public TrpcModule(String path, TrpcService service, TrpcService... services)
      Creates a new instance of TrpcModule with 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 be null.
      service - The primary tRPC service to register. Must not be null.
      services - Additional tRPC services to register (if any). Optional and may be omitted.
    • TrpcModule

      public TrpcModule(TrpcService service, TrpcService... services)
      Constructs a new TrpcModule with the default base path: trpc and the provided services.
      Parameters:
      service - The primary tRPC service to register. Must not be null.
      services - Additional tRPC services to register (if any). Optional and may be omitted.
  • Method Details

    • install

      public void install(io.jooby.Jooby app) throws Exception
      Installs the tRPC extension into the Jooby application.

      During installation, this method performs the following setup:

      • Validates that a TrpcParser is available in the service registry.
      • Initializes the registry map for custom Class to TrpcErrorCode mappings, allowing developers to map domain exceptions to specific tRPC errors.
      • Registers the TrpcErrorHandler globally to intercept and correctly format exceptions thrown from /trpc/* endpoints.
      Specified by:
      install in interface io.jooby.Extension
      Parameters:
      app - The current Jooby application.
      Throws:
      Exception - If a required service (such as the TrpcParser) is missing from the registry.