The best 8 Java restful framework _java

Source: Internet
Author: User
Tags datetime documentation fast web glassfish java web java se

Over the past year, more and more Java frameworks have sprung up. Like JavaScript, everyone thinks they know what a good frame should be. Even my old grandmother now uses a framework that I have never heard of and may never use. Joke to joke, can do almost anything bloated frame market is saturated, but how to judge it? This article is designed to provide the best Java restfulful framework. I'm only introducing lightweight products, skipping over those bloated, overly-designed frameworks. At the same time, I just want them to be stable and mature, providing simple, lightweight features. I only break this rule when I introduce play frameworks, for the reason given later. Which Java restful framework to use in future projects depends entirely on your current requirements. To make your choice, I'll list the most prominent frame features and hopefully this will save you some time.

Dropwizard

Birth time: 2011
Rating: 4.5/5

Dropwizard provides a stable, mature Java library and encapsulates it into a simple lightweight package.
Dropwizard between frames and libraries. It provides all the necessary to develop a Web application. Because of the built-in modularity, an application can maintain small and lean features, reduce development and maintenance time, and reduce the burden.
Dropwizard uses an existing Jetty HTTP library and embeds it into your project without the need for an external server. All Dropwizard projects have a main method to manage the built in HTTP server.

Link
Official Site GITHUB Documents

Advantages

Fast Project building and start-up

of modular

Incredibly fast (at least according to the metric measured results)

Jetty for HTTP, Jersey for REST, and Jackson for JSON

Other libraries are also supported, such as mustache, Logback, JDBI, Hibernate Validator, guava, ...

Using Metrics support monitoring

The main method launches the Jetty server, which makes it easy to debug and maintain

Strong community Strength

Disadvantages

Dropwizard documentation is a major source of knowledge, but not excellent. You may need to search and discover the documentation for the third party class library.

Because errors are treated as plain text for some reason, if you want the response to always be JSON, this may be problematic

Make sure you use the latest dropwizard, and some older versions use obsolete Third-party libraries. And early dropwizzard are hard to upgrade.

Example

 package com.example.helloworld;
Import io.dropwizard.Application;
Import Io.dropwizard.setup.Bootstrap;
Import io.dropwizard.setup.Environment;
Import Com.example.helloworld.resources.HelloWorldResource;
 
Import Com.example.helloworld.health.TemplateHealthCheck; public class Helloworldapplication extends application 
 

Annotations
Individuals do not want to recommend this framework for large projects. But if you want to try, you won't be disappointed. The main thing is that this framework uses the best modern Java Web Components and assembles them into a simple and easy-to-use framework.
Unfortunately, this has also brought about its problems. The combination of these libraries can lead to unforeseen problems. That's why I lost 0.5 stars to it, not 5 stars.

Jersey

Birth time: (Jersey 2.X)
Rating: 5/5

The Jersey RESTful Framework is an Open-source RESTful framework that implements the Jax-rs (JSR 311 & JSR 339) specification. It expands the JAX-RS implementation and provides additional features and tools to further simplify RESTful service and client development. Although relatively new, it is already a product-level RESTful service and client framework.

Link
Official Site GITHUB Documents

Advantages

Excellent documentation and examples

Fast

Super easy to Route

Smooth JUnit Integration

Personally, the JAX-RS implementation is better than the MVC framework when developing RESTful service.

can be integrated into other libraries/frameworks (Grizzly, Netty). This may also be the reason why many products use it.

Support for asynchronous links

Don't like servlet container? You can use jersey without them.

WADL, Xml/json support

Included in the GlassFish

Disadvantages

Jersey 2.0+ uses a number of complex dependency injection implementations

May not be a bad thing. Jersey 1.X is implemented using older Jax-rs

A lot of third-party libraries only support Jersey 1.X, not available at Jersey 2.X

Example

Package Org.glassfish.jersey.examples.helloworld;
 
Import Javax.ws.rs.GET;
Import Javax.ws.rs.Path;
Import javax.ws.rs.Produces;
 
@Path ("HelloWorld") public
class Helloworldresource {public
   static final String cliched_message = ' Hello world !" ;
 
@GET
@Produces ("Text/plain") public
   String Gethello () {return
     cliched_message;
   }
}

Annotations
Jersey is my choice, 5 stars.

Ninja Web Framework

Birth time: 2012
Rating: 3.5/5
The Ninja web framework is a full stack of Java Web frameworks. Stable, fast, reliable, product level.
It provides everything from developing, testing, publishing, and maintaining RESTful Web applications (Servlets, Guice, JPA, flyway migrations, Maven, etc).
Like Dropwizzard, the Ninja Web Framework is an integrated software stack. You don't have to build your own, just use Maven archetype to build a new project and import it into the IDE to start coding.

Link
Official Site GITHUB Documents

Advantages

Fast

Fast Project building and start-up

of modular

XML, HTML, JSON rendering

Other libraries (such as Guice, logback, guava, etc) are also supported.

Good data persistence and caching

Don't like servlet container? You can choose the container you like

If you don't like the container at all, you can use the standalone mode to use jetty as a self executing jar

Disadvantages

Again, just like Dropwizzard, documents have but not good enough. It took me a long time to understand it. This framework also relies on many other libraries, and sometimes it's cumbersome to get the information you need.

Not very well known, small community. Rumor has it that this framework was created by those who switched to Scala's play 2.X user

Example

package controllers;
 
public class Applicationcontroller {public result   
 
   index () {person person
 
     = new person ();
     Person.name = "John Johnson";
 
     Return Results.json (). render (person);
 
   }

Annotations
It looks good, but I'll throw it aside before it matures.

Play Framework

Birth time: 2011
Rating: 4/5

Use the play Framework to easily create, build, and publish Web applications that support Java & Scala. It uses Akka, based on a lightweight, stateless architecture. It should be applied to a large scale of low CPU and memory consumption applications.

Link
Official Site GITHUB Documents

Advantages

Easy to develop

Quick, but there are no other frames fast

Supports non-blocking I/O based on Netty. It's good to handle remote calls in parallel.

The community is big.

Fast Project building and start-up

of modular

Mvc

REST, Json/xml, Web Sockets, non-blocking I/O

Just refresh the browser to see the latest changes

Support Async

There are books published.

Disadvantages

Version 2.0 is the most controversial Java framework. Switch to the switch to Scala made some Java developers outraged.

Not backward compatible; Play 2.X has rewritten

Supposedly lightweight, but somewhat bloated

SBT build Tools. The so-called Maven killer, but never good to replace it. Difficult to learn and configure

Non-servlet

Breaking Changes across releases

Example

Package Controllers
 
Import play.api._
import Play.api.mvc._
 
class application extends Controller {
 
  def hello (name:string) = Action {
   ok ("Hello" + name +!)
  }
 
}

Annotations
Complaining back to complaining, I have always liked and preferred this framework. Unfortunately, I can only give it 4 stars. I firmly believe that the JAX-RS framework is more suitable for RESTful Web services.

Restexpress

Birth time: 2009
Rating: 3/5

Restexpress is a container-less lightweight Netty HTTP stack wrapper to make it easier to create Java RESTful services.
The restexpress goal is to support the best RESTful practice.

Link
GITHUB

Advantages

The real micro-frame

Top performance, fast, reliable

Xml/json

One of the oldest and most stable RESTful frames

Disadvantages

No document

Almost no support

A small community.

Example

Package com.example;
 
Import java.io.IOException;
 
Import Io.netty.handler.codec.http.HttpMethod;
Import org.restexpress.RestExpress;
 
public class Main
{public
   static restexpress startserver (string[] args) throws IOException
   {
     Restexpress Server = new Restexpress ();
     MyResource r = new MyResource ();
 
     Server.uri ("/myapp/myresource", R)
       . Method (Httpmethod.get)
       . noserialization ();
 
     Server.uri ("/myapp/myresource", R)
       . Method (Httpmethod.post);
 
     Server.bind (8080);
     return server;
   }
 
   public static void Main (string[] args) throws Exception
   {
     restexpress server = StartServer (args);
     System.out.println ("Hit Enter to stop it ...");
     System.in.read ();
     Server.shutdown ();
   }

Annotations
Even though the framework is super fast, I don't want to recommend it. Lack of documentation and unsupported support make it a poor framework. Give it 3 stars for the sake of speed.

Restlet

Birth time: 2005
Rating: 4.5/5

Restlet helps Java programmers build large-scale, fast web APIs that conform to RESTful schema patterns.
It provides a powerful routing and filtering system. A unified client/server Java API. Meet all the major platforms (Java Se/ee, Google appengine, OSGi, GWT, Android) and provide countless extensions to meet the needs of programmers.
As far as I know, it is the first Java RESTful web framework. A lot of companies are using it, but you probably never heard of it, as if it was already invisible.

Link
Official Site GITHUB Documents

Advantages

Powerful

Enterprise-Class Framework

Multi-platform Java SE, Java EE, Google Web Toolkit, Google AppEngine, Android, OSGi environments

Support Jax-rs (just like Jersey)

Most advanced RESTful support

of modular

Support for other libraries

Development has been active

Intelligent URL binding, fully functional URI routing

There are books related to

Disadvantages

A very steep learning curve

Closed the community, though StackOverflow was still open on the

No longer popular, more because the play Framework and Jersey

Example

public class Part03 extends Serverresource {public
 
   static void Main (string[] args) throws Exception {
     //Create T He HTTP server and listen on port 8182
     new Server (Protocol.http, 8182, Part03. Class). Start ();
 
   @Get ("TXT") public
   String toString () {return
     ' Hello, world ';
   }
 
}

Annotations
Although this framework has been popular, but to its and the current degree of completion, I can not give it 5 stars.

Restx

Birth time: 2013
Rating: 3.5/5

RESTX is a lightweight, modular, feature-wide, super fast Open source Java REST framework.

Link
Official Site GITHUB Documents

Advantages

Fast, lightweight

Easy to build

The real micro-frame

of modular

Support for other libraries

Support MongoDB

Disadvantages

Unfriendly and confusing document. I expect a little better documentation for this type of framework.

Too young

Asynchronous async is not currently supported

Example

@GET ("/message/{id}") public message
   SayHello (string ID,//path param
               string who//query param
               ) {
     re Turn new Message (). Setmessage (String.Format (
         "Hello%s, it's%s", who
         , DateTime.Now (). toString ("HH:mm:ss")) ;
   }
@POST ("/message/{id}") public message
   SayHello (String ID,//path param
               msg//body param
               ) {
   return msg.setmessage (String.Format (
         "%s @%s",
         msg.getmessage (), DateTime.Now (). toString ("HH:mm:ss") ));
   }

Annotations
I don't really spend too much time on this frame. It's not worth spending too much energy on another frame, I mean, the Java framework market is becoming more fragmented, like the JavaScript market, which should stop this trend.

Spark Framework

Birth time: 2011
Rating: 3.5/5
Instead of messing with Apache's big data frame Spark, the Spark framework here is a lightweight Java web framework for rapid development (50% Spark users to create REST APIs using Spark). It is inspired by the Ruby framework Sinatra.

It has a minimized kernel of less than 1M, providing all the basic features that are used to build RESTful or traditional Web applications.

Link
Official Site GITHUB Documents

Advantages

Quick, lightweight

Excellent Quick prototyping

Easy to build

Often paired with Angularjs

The real micro-frame

Using Jetty

Can be used in a container or run independently

Disadvantages

Documentation can be better, it's not for beginners

Not suitable for large projects

Community Small

Example

Import static Spark. spark.*;
 
public class HelloWorld {public
  static void Main (string[] args) {get
    ("/hello", (req, res)-> "Hello World" );
  }
}

Annotations
This framework is suitable for initial development. Used primarily as a small project or prototype.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.