Java Rest Intro - 8 Top Java RESTful Micro Framework (english)
http://www.gajotres.net/best-available-java-restful-micro-frameworks/
With each passing year, Java framework scene becomes more and more densely populated. Similar to JavaScript, everyone thinks they know what a good framework should feature and look. Even my grandmother is now using a framework I never heard off or probably won’t ever use. Joking aside, the market is saturated with bloated frameworks that can do almost everything, but for what price?
This article is intended to show you currently best available Java RESTful Micro Frameworks. I will try to review only (almost) lightweight products altogether skipping everything that looks bloated and over-featured. At the same time, I want them stable and mature, offering simple, light-weight “getting things done” features. I will break this rule only once covering Play Framework, but more about this topic later.
Which Java RESTful Micro Framework will you use in your next project will depend solely on your current needs. To make your life easier, I will list most prominent framework features. Hopefully, this will save some of your time.
PS. If you want my help, if possible (even if it takes you some time to do that), create a working example I can play with. Use Plunker for AngularJS based questions or jsFiddle for jQuery/jQuery Mobile based questions.
Table of Contents
- Best available PHP RESTful Micro Frameworks
- Top 8 Java RESTful Micro Frameworks
Intro
Before we go any further, take a look at a list of my chosen eight, in alphabetical order:
- Dropwizard
- Jersey
- Ninja Web Framework
- Play Framework
- RestExpress
- Restlet
- Restx
- Spark Framework
Introduction date: 2011
Rating: 4.5/5
Dropwizard provides stable, mature Java libraries assembled into a simple, light-weight package providing you with everything that lets you focus on getting things done.
Dropwizard walks the line between a library and a framework. It should provide reliable implementations of everything your web application needs and requires. Because of built-in modularity, an application remains small and lean, reducing development and maintenance time and possible burdens.
Dropwizard uses existing Jetty HTTP library embedding it directly into your project, this way external application server is not needed. All Dropwizard projects have a main method which manages built-in HTTP server.
Links
Official Site GitHub Documentation
Pro
- Quick project building and bootstraping
- Modularity
- Incredibly fast (at least according to built-in metrics)
- Comes with a Jetty for HTTP, Jersey for REST, and Jackson for JSON.
- Other libraries are also supported, you may or may not use them (like Mustache, Logback, JDBI, Hibernate Validator, Guava, ….).
- Monitoring support with Metrics
- Main method which starts the Jetty server makes it easy to debug and maintain
- Large community support
Con
- Dropwizard documentation is a great source of knowledge though I wouldn’t call it excellent. You will need to search and dig through another 3rd party library documentation’s if you require finding something specific related to other libraries.
- For some reason errors are handled as plain text, which can be problematic if you expect everything treated as a JSON response.
- Make sure you’re using newer Dropwizard versions; some of the older ones are using deprecated 3rd party libraries. Plus earlier Dropwizzard versions were harder to upgrade.
Example
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
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<HelloWorldConfiguration> { public static void main(String[] args) throws Exception { new HelloWorldApplication().run(args); } @Override public String getName() { return "hello-world"; } @Override public void initialize(Bootstrap<HelloWorldConfiguration> bootstrap) { // nothing to do yet } @Override public void run(HelloWorldConfiguration configuration, Environment environment) { // nothing to do yet }} |
Author notes
Personally, I don’t want to recommend this framework for larger projects, but if you’re willing to give it a try, you will not be disappointed. If anything because, primarily this framework uses the best modern Java based web application components available, packaged into an easy-to-use framework.
Unfortunately what makes it great also makes it problematic. Mixing all those libraries can cause unforeseen problems, that’s why I gave it 1/2 star less than 5 of 5.
Introduction date: 2012 (Jersey 2.X)
Rating: 5/5
Jersey RESTful framework is open source framework built upon a JAX-RS (JSR 311 & JSR 339) specification. It provides its API that extends existing JAX-RS reference implementation with additional features and utilities to further simplify RESTful service and client development. Though relatively young (compared to other similar frameworks mentioned in this article) it’s production ready environment meant for RESTful service and client development.
Links
Official Site GitHub Documentation
Pro
- Excellent documentation + working examples.
- Fast and cutting edge
- Extremely easy routing
- Smooth JUnit integration
- Personally, when working with RESTful services, JAX-RS implementations are better then MVC frameworks. Though, through some point, it supports MVC.
- Plays nice with other libraries/frameworks (Grizzly, Netty). Which is probably the main reason it can be found bundled with so many other products.
- Supports true asynchronous connections
- Don’t like servlet container? You don’t need to use it with Jersey.
- WADL, XML/JSON support
- Included with Glassfish
Con
- Jersey 2.0+ uses a somewhat messy dependency injection implemetation
- Though not a bad thing, Jersey 1.X uses an older JAX-RS implementation then Jersey 2.X
- A large amount of online resources (3rd party) are related to Jersey 1.X making them unsuitable for Jersey 2.X
Example
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
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; }} |
Author notes
Jersey (like Play) is a framework of my choice, easily 5/5.
Introduction date: 2012
Rating: 3.5/5 (I’m not impressed enough)
Ninja Web Framework is a full-stack web framework for Java. Stable, fast, reliable, and super productive.
It provides everything you need to develop, test, deploy, and maintain your RESTful web application (Servlets, Guice, JPA, Flyway migrations, Maven, etc.).
Just like DropWizzard, Ninja Web Framework is an integrated software stack. You don’t have to setup everything on your own, just generate a new project from using Maven archetype, import it into available IDE and start coding.
Links
Official Site GitHub Documentation
Pro
- Fast
- Quick project building and bootstrapping
- Modularity
- XML, HTML, JSON rendering
- Other libraries are also supported, you may or may not use them (like Guice, Logback, Guava, etc.).
- Good data persistence support and caching
- Don’t like servlet container? Use any container you like.
- Don’t want to use containers at all? Use it in stand-alone mode, as a self-executing jar package bundled with Jetty.
Con
- Again, just like with DropWizzard, provided documentation is good but not good enough. It took me some time to get acquainted. Also, this framework relies on so many other libraries that sometimes it can become cumbersome to find needed information.
- Not that famous, so expect much smaller community. According to some rumors, this framework was built by/for Play users who didn’t like Play 2.X switching mainly to Scala. Please leave a comment below if you think this is not correct.
Example
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
package controllers;public class ApplicationController { public Result index() { Person person = new Person(); person.name = "John Johnson"; return Results.json().render(person); }} |
Author notes
It sounds like a great framework, but I will leave it on the side until it matures a little bit more.
-
Antonio Garcia
-
Edgar Espina
-
Ahmmad Ismail
-
-
Dragan Gaić
-
C B Newham
-
Dragan Gaić
-
Dragan Gaić
-
Yoram
-
-
Jay Ma
-
Danio
-
Jonathan Airey
-
Yohanes Pradono
-
Ferran Maylinch
-
Madhu Sudhan
-
-
-
Yohanes Pradono
-
Hestia
-
Steve Hu
-
Johanneke
posted on 2017-09-18 12:01 fanbird2008 阅读(308) 评论(0) 收藏 举报
浙公网安备 33010602011771号