Implementing a REST API in Java

2,279 views
Skip to first unread message

ccl...@dieselpoint.com

unread,
Aug 18, 2016, 12:48:38 PM8/18/16
to grpc.io
Our app has a REST API we've implemented using Jax-RS, Jetty, and Resteasy.

I'd like to port the whole thing to gRPC, and offer both a gRPC and a JSON/REST interface to our customers.

Our product is not yet released, so I have some flexibility in redesigning the API. But it's going to be necessary to support query parameters in the URL, i.e. GET /hello?foo=bar

Is this possible using the Java code? Maybe there's a Netty component for it?

(I see that there is a way to do it in Go: https://github.com/grpc-ecosystem/grpc-gateway. Need the same thing in Java.)

 

Louis Ryan

unread,
Aug 18, 2016, 1:36:50 PM8/18/16
to ccl...@dieselpoint.com, grpc.io
I don't think anyone is looking at providing the same functionality as a Java library today but we've talked about building it into nginx if that would help. Contributions certainly welcome

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to grp...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/2f228f50-9cbc-4238-a2d7-a885e3fb58d5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Paul Johnston

unread,
Aug 18, 2016, 5:51:26 PM8/18/16
to grpc.io, ccl...@dieselpoint.com
Maybe it's possible to use what you have already and use that as the reverse-proxy to a yet-to-be-written gRPC service for some of the most performance-critical parts of your API, and see if that gRPC offering works for you and your customers.  Once you discover the patterns you like, you could consider writing a protoc plugin that generates code in the REST style familiar to your existing codebase.

ccl...@dieselpoint.com

unread,
Aug 24, 2016, 2:06:45 PM8/24/16
to grpc.io, ccl...@dieselpoint.com
Could you give me a bit of direction here? I can't make heads or tails of the internal Grpc server code, nor can I find where I would add a filter to handle json-over-http calls.

All I really need is to know where to put some kind of interceptor, filter, or hook that can examine incoming headers, and if it's a request for json, deserialize, handle, serialize, and respond. My guess is that it wouldn't be to tough to add a proxy layer somewhere. A quick example would save me hours...

Louis Ryan

unread,
Aug 25, 2016, 7:38:05 PM8/25/16
to ccl...@dieselpoint.com, grpc.io
I think you don't want to write a 'filter' over the GRPC server code. I think Paul was suggesting that you write your own servlet that manually wraps a generated GRPC client-stub and produces the output that you want. You can then run that code in the same process and connect to a GRPC server using the InProcessServer and InProcessChannel or you can have the client stub talk to a remote server. 

i.e you manually emulate what the GRPC-go gateway does to see if that's useful for you

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to grp...@googlegroups.com.

matthe...@market2x.com

unread,
Sep 2, 2016, 1:02:06 AM9/2/16
to grpc.io, ccl...@dieselpoint.com
We use grpc-gateway for exactly this and we program in Java. The grpc-gateway is an independent reverse proxy layer that get compiled into an executable, so it doesn't matter it is in Go. You run it typically on the same server as you grpc service (written in Java) as a separate process. I'm not a Go programmer and setting it up required tweaking one file of Go code that I copy and pasted from the examples. 

srssr...@gmail.com

unread,
Feb 15, 2018, 1:03:30 AM2/15/18
to grpc.io
Hi Matthew,

Can you please tell what tweaking you have done in one Go file to make it work ? 

Regards,
Srijith

sumitth...@gmail.com

unread,
Jun 7, 2018, 5:21:34 AM6/7/18
to grpc.io

Mahesh Kanote

unread,
Jun 7, 2018, 10:39:19 AM6/7/18
to sumitth...@gmail.com, grpc.io
You can also check https://www.envoyproxy.io

--
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 post to this group, send email to grp...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages