What are the best frameworks for implementing both client and server REST frameworks in Java? I've been struggling a little to find an easy to use solution.
Update: Both Jersey and Restlet seem like good options. We'll probably use Restlet but we'll experiment with both.
Jersey is really easy for both. To write web services, you use annotations:
@Path("/helloworld")
public class HelloWorldResource {
// The Java method will process HTTP GET requests
@GET
// The Java method will produce content identified by the MIME Media
// type "text/plain"
@Produces("text/plain")
public String helloWorld() {
// Return some cliched textual content
return "Hello World";
}
}
For a client:
Client client = Client.create();
WebResource webResource = client.resource("http://localhost:8080/helloworld");
String s = webResource.get(String.class);
System.out.println(s); // prints Hello World