tags:

views:

1512

answers:

6

If I want to use Java to create a REST client, what should I use?

Can i use CXF?

+3  A: 

I've had success using HttpClient from Jakarta Commons.

Also Java comes with URLConnection but you might want to look at this comparison with HttpClient.

Apache CXF does support REST clients (see here) but seems like overkill (CXF is a general 'services' framework and therefore complicated with support for CORBA, SOAP etc.)

Matthew Murdoch
HttpClient and URLConnection are both good options, but I'd recommend using them with the Restlet API, which is an abstraction layer one level up from these low-level classes. Restlet lets you write code which is decoupled from any specific client library, and then swap in and out whichever client library you prefer, using its "connector" paradigm.
Avi Flax
Apache CXF 2.2.1 also contains a REST client. See: http://cwiki.apache.org/CXF20DOC/jax-rs.html#JAX-RS-ClientAPI
Daniel Kulp
Thank you @Daniel, I'll update the answer.
Matthew Murdoch
+3  A: 

There is a Jersey client API that allows you to easily implement clients in Java

Brian Agnew
+6  A: 

I used Restlet. I really liked it and wrote a blog post about my experience.

Vinnie
Oh sorry - I see you said REST "client". My bad. Restlet is used to to create the server-side implementation. I've also used Http Unit to test this service.
Vinnie
Actually, Restlet is a full-blown API and implementation for creating both RESTful Servers **and** clients. I've written many REST clients using Restlet, with excellent results.
Avi Flax
A: 

imo there is hardly a need for a framework, simply use the servlet API and implement the request methods you need aka POST / GET / PUT / DELETE / HEAD

an example: http://www.exampledepot.com/egs/javax.servlet/com_mycompany_MyServlet.html

KingInk
A: 

I think it really depends on the app and your environment, but I find resteasy really easy (since it is so declarative) and configurable. See chapter 30 for the client documentation.

disown
A: 

Use HTTP4e REST client add-on for Eclipse. It is simple to use and has Java/C#/Ruby/Flex/ActionScript/etc.. one click code generation.

Atanas Roussev