Can we use Rest and gRPC in together in spring-boot/java application

2,932 views
Skip to first unread message

Pawan Shriwas

unread,
Mar 8, 2021, 10:26:22 AM3/8/21
to grpc.io
Hi Guys, 

I there any way where  we can use Rest and gRPC in together in spring-boot/java application. 

Thanks in advance.


Sanjay Pujare

unread,
Mar 8, 2021, 11:25:37 AM3/8/21
to Pawan Shriwas, grpc.io
Yes, you can use the gRPC client for talking to gRPC services and a REST client for talking to REST services assuming you are talking about client side coexistence.

--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/7614e847-21bc-4571-9231-c433ac6a1fadn%40googlegroups.com.

Pawan Shriwas

unread,
Mar 9, 2021, 3:00:37 AM3/9/21
to grpc.io
I am talking about the case where my spring boot application server which is right now equipped with rest interfaces, I want it to be also equipped with gRPC interfaces for same service layer so that my same micro-service support same service interface for rest and gRCP.

for more understanding i have draw the case below that i need rest and grcp in my application, let me know if that is feasible.

Untitled Diagram (1).png

  

Mahesh Kanote

unread,
Mar 9, 2021, 3:08:23 AM3/9/21
to Pawan Shriwas, grpc.io
Yes, we can do that by running grpc server on different port. 

Thanks,
Mahewj

Russell Wu

unread,
Mar 9, 2021, 3:39:32 AM3/9/21
to Mahesh Kanote, Pawan Shriwas, grpc.io
I think you can achieve that in many different ways, some options:
1. Add a service controller layer that implements the actual business logic between grpc/rest interface implementations and your DAO.
2. Use envoy to provide a rest proxy in front of grpc service


Sanjay Pujare

unread,
Mar 9, 2021, 11:57:25 AM3/9/21
to Russell Wu, Mahesh Kanote, Pawan Shriwas, grpc.io
Envoy is unnecessary if you run the gRPC server on a different port.

Russell Wu

unread,
Mar 9, 2021, 7:46:29 PM3/9/21
to Sanjay Pujare, Mahesh Kanote, Pawan Shriwas, grpc.io
Oh. I misread the question. I was talking about a scenario where you have a grpc interface already and looking to add a rest interface. My bad. 

Jörg Hohwiller

unread,
Mar 10, 2021, 5:31:50 PM3/10/21
to grpc.io
Hi there,

Just in case someone is interested:
I am working an a framework that supports format-agnostic marshalling:
On top of that there are real Java beans with awesome features and automatic marhsalling:
On top of that you can implement RPC services in an agnostic way with sync/async/reactive support:
With all that you can implement your server with very little code and on one HTTP/2 port.
Users can invoke your service and choose the format via content-type as JSON, YAML, XML, or ProtoBuf/gRPC.
Also the provided client can support all this with synchronous and asynchronous usage.
All runs in JVM, as well as in the browser cross-compiled as JS/WASM via TeaVM, or cloud-native via GraalVM.

Still a whole lot of work to do but maybe someone here also likes to join in or have a look...
Most promising part of the project however is this one:

Yes, I know that we are reinventing the wheel but there are reasons:

Cheers
  Jörg
Reply all
Reply to author
Forward
0 new messages