Annotation Interface Trpc


@Target({TYPE,METHOD}) @Retention(RUNTIME) @Documented public @interface Trpc
Marks a controller class or a specific route method for tRPC TypeScript generation.

When applied to a class, it defines a namespace for the tRPC router. All tRPC-annotated methods within the class will be grouped under this namespace in the generated TypeScript AppRouter.

Defining Procedures:

There are two ways to expose a method as a tRPC procedure:

  • Explicit tRPC Annotations: Use Trpc.Query for read-only operations (mapped to HTTP GET) and Trpc.Mutation for state-changing operations (mapped to HTTP POST).
  • Hybrid HTTP Annotations: Combine the base @Trpc annotation with standard HTTP annotations. A @GET annotation maps to a query, while @POST, @PUT, @PATCH, and @DELETE map to a mutation.

Network Payloads:

Because tRPC natively supports only a single input payload, Java methods with multiple parameters will automatically require a JSON array (Tuple) from the frontend client. Framework parameters like io.jooby.Context are ignored during payload calculation.

Example:


 @Trpc("movies") // Defines the 'movies' namespace
 public class MovieService {

 @Trpc.Query // Becomes 'movies.list' query
 public List<Movie> list() { ... }

 @Trpc // Hybrid approach: Becomes 'movies.delete' mutation
 @DELETE
 public void delete(int id) { ... }
 }
 
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static @interface 
    Marks a method as a tRPC mutation.
    static @interface 
    Marks a method as a tRPC query.
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    Custom name for the tRPC procedure or namespace.
  • Element Details

    • value

      String value
      Custom name for the tRPC procedure or namespace.

      If applied to a method, this overrides the generated procedure name. If applied to a class, this overrides the generated namespace in the AppRouter.

      Returns:
      The custom procedure or namespace name. Empty by default, which means the generator will use the Java method or class name.
      Default:
      ""