Yaba Yaba - 3 years ago 234
reST (reStructuredText) Question

Rest clients for Java?

With JSR 311 and it's implementations we have a powerful standard for exposing Java objects via Rest. However on the client side there seems to be something missing that is comparable to Apache Axis for SOAP - something that hides the web service and marshals the data transparently back to Java objects.

How do you create Java RESTful clients? Using HTTPConnection and manual parsing of the result? Or specialized clients for e.g. Jersey or Apache CXR?

Answer Source

This is an old question (2008) so there are many more options now than there were then:

UPDATE circa 2014:

The new kid on the block which provides NIO support (although truthfully I don't think this really improves performance for clients like it does servers).

UPDATE 2016:

  • OkHttp - Supports newer HTTP protocols (SPDY and HTTP2). Works on Android. Unfortunately it does not offer a true reactor-loop based async option (see Ning and HTTP components above). However if you use the newer HTTP2 protocol this is less of a problem (assuming connection count is problem).
  • Retrofit - Will auto create clients based on interface stubs similar to some Jersey and CXF extensions. Uses OkHttp.
  • Apache HttpComponents 5 will supposedly have HTTP2 support

A caveat on picking HTTP/REST clients. Make sure to check what your framework stack is using for an HTTP client, how it does threading, and ideally use the same client if it offers one. That is if your using something like Vert.x or Play you may want to try to use its backing client to participate in whatever bus or reactor loop the framework provides... otherwise be prepared for possibly interesting threading issues.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download