最简单的框架来实现Java REST Web服务

Mar*_*eon 29 java rest web-services jersey restlet

在Java中实现客户端和服务器REST框架的最佳框架是什么?我一直在努力寻找一个易于使用的解决方案.

更新:Jersey和Restlet看起来都是不错的选择.我们可能会使用Restlet但我们会尝试两者.

Dro*_*roo 24

泽西岛对两者都很容易.要编写Web服务,请使用注释:

@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";
    }
}
Run Code Online (Sandbox Code Playgroud)

对于客户:

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
Run Code Online (Sandbox Code Playgroud)


Ste*_*hen 20

Restlet听起来应该提供你想要的东西:

  • 支持客户端和服务器(在相对对称的api中)
  • 智能网址绑定
  • mime类型理解(给定接受的mime类型,它将询问您的资源在该类型中的表示)
  • 支持JAX-RS注释(就像Jersey一样)

  • +1我在大型生产应用程序中使用Restlet获得了出色的结果. (4认同)

jos*_*hua 6

看看dropwizard也是如此.