https://github.com/linux-china/trpc-spring-boot-starter
Spring Boot Starter for tRPC
https://github.com/linux-china/trpc-spring-boot-starter
Last synced: 11 months ago
JSON representation
Spring Boot Starter for tRPC
- Host: GitHub
- URL: https://github.com/linux-china/trpc-spring-boot-starter
- Owner: linux-china
- License: apache-2.0
- Created: 2023-01-11T02:50:04.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-03-15T01:44:17.000Z (over 3 years ago)
- Last Synced: 2025-07-15T02:51:19.563Z (12 months ago)
- Language: Java
- Size: 22.5 KB
- Stars: 12
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
Spring Boot Starter tRPC
=============================================
Spring Boot starter for [tRPC](https://trpc.io/), and compatible with webmvc/webflux of Spring Boot 2.x/3.0.
# Get Started
* Add dependency in your pom.xml
```xml
org.mvnsearch
trpc-spring-boot-starter
0.1.0
```
* Write controller for tRPC query/mutate
```java
import org.mvnsearch.spring.boot.trpc.TrpcInput;
import org.mvnsearch.spring.boot.trpc.TrpcMutate;
import org.mvnsearch.spring.boot.trpc.TrpcQuery;
import org.mvnsearch.spring.boot.trpc.TrpcResponse;
import org.springframework.stereotype.Controller;
import java.util.UUID;
@Controller
public class TrpcHelloController {
record Hello(String name) {
}
@TrpcQuery("/greeting.hello")
public TrpcResponse hello(@TrpcInput Hello hello) {
return TrpcResponse.of("Hello " + hello.name);
}
record Poster(String id, String title, String text) {
}
@TrpcMutate("/poster.createPost")
public TrpcResponse createPost(@TrpcInput Poster poster) {
return TrpcResponse.of(new Poster(UUID.randomUUID().toString(), poster.title, poster.text));
}
}
```
* Test your tRPC service with [httpx](https://httpx.sh/docs/tutorial-basics/trpc-testing)
```
### trpc query
TRPC http://localhost:8080/greeting.hello
Content-Type: application/json
{
"name": "world"
}
### trpc mutate
TRPCM http://localhost:8080/poster.createPost
Content-Type: application/json
{
"title": "title",
"text": "hello world"
}
```
# FAQ
### Could I use Spring Framework 6 HTTP Interface with tRPC?
Please refer to [tRPC Spring HTTP Interface](https://github.com/linux-china/trpc-http-interface)
# References
* tRPC: https://trpc.io/
* tRPC testing: https://servicex.sh/docs/tutorial-basics/trpc-testing
* tRPC Spring HTTP Interface: https://github.com/linux-china/trpc-http-interface