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.Queryfor read-only operations (mapped to HTTP GET) andTrpc.Mutationfor state-changing operations (mapped to HTTP POST). - Hybrid HTTP Annotations: Combine the base
@Trpcannotation with standard HTTP annotations. A@GETannotation maps to a query, while@POST,@PUT,@PATCH, and@DELETEmap 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 ClassesModifier and TypeClassDescriptionstatic @interfaceMarks a method as a tRPC mutation.static @interfaceMarks a method as a tRPC query. -
Optional Element Summary
Optional Elements
-
Element Details
-
value
String valueCustom 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:
""
-