views:

5625

answers:

8

Which REST API do you prefer - Jersey or Restlet? This would encompass both the client and server API-s.

We really need to just pick one and kick the tires around but I was curious what the community thinks.

Restlet seems simpler and better documented to me. I've had a hard time even finding decent documentation about the Jersey client API.

A: 

Since this is a subjective question, I have a subjective answer.

I prefer to write the code myself and not use any framework to do the work for me. Why? My opinion is that you should write your own web service so that you completely understand how it works rather than letting some framework do all of the work for you which results in the you, the developer, not really knowing what the code is doing.

Once I had written a REST web service or two from scratch and knew how everything worked I tried to use the frameworks but I found them to be bloated and included many things I had no need of.

ChadNC
Fair enough. I do dislike "over-abstraction". Restlet seems to use less abstraction.
Marcus
And why stop there? You should also write your own ORM layer, DI container, web server, compiler and OS while you're at it.
ChssPly76
First though, you must build your own computer.
jon hanson
@ChssPly76, @jonhanson, your reductio ad absurdum argument would be valid if @ChadNC took the position that rolling your own was always superior. Instead, his position is that you should try rolling your own so that a) you learn the domain and b) you're in a better position to weigh the pros and cons of a framework. Frameworks have cost; there's a number of valid reasons those costs can be greater than rolling your own.
toolbear74
@Marcus, I found the opposite to be the case with RESTlet. Too much abstraction and high-falutin' OO design.
toolbear74
+3  A: 

Don't forget good 'ole Spring too. They have plenty of pieces that support REST - the easiest being a normal Spring Controller that simple implements all the standard Http verbs.

Gandalf
+8  A: 

A RESTful framework such as Restlet does not just provide handling of HTTP calls, otherwise the Servlet API would be sufficient. The idea is to support advanced features of HTTP such as content negotiation, conditional processing, caching out of the box and to provide a canvas for a RESTful design of your Web applications based on Resources, URIs and Representations. See a more complete list of features here: http://www.restlet.org/about/features

Also, Restlet isn't bloated and can be used either as a library or as a framework: it isn't unecessarily intrusive. Its core is a standalone JAR of about 500 Kb (no dependency beside Java SE 5.0), containing the Restlet API and engine, plus default client and server connectors for HTTP or local files. It can replace an HTTP server such as Apache HTTPd with static file serving and a complete RESTful security API. All other features are provided as optional extensions.

To get started, see the first steps example: http://www.restlet.org/documentation/2.0/firstSteps

Best regards,

Jerome Louvel

Restlet ~ Founder and Lead developer ~ http://www.restlet.org

Noelios Technologies ~ Co-founder ~ http://www.noelios.com

Jerome Louvel
Not to mention that remote resources exposed via your REST API are not likely at the same granularity as your POJOs. So just simply annotating POJOs via Jersey doesn't really solve the impedance mismatch elegantly. Subclassing Restlet Resources seems more appropriate to me.
Kevin Pauli
A: 

You might want to consider NetKernel 4.

It is a REST software platform that is written in Java, runs on the Java VM and supports languages that compile to or run on the JVM (Scala, Ruby, Python, JavaScript, XQuery, XSLT, etc.).

Since it is a REST software platform, the mapping from external REST web services to internal endpoint implementations is straight forward.

NetKernel can be run as its own platform or it can be instantiated as a POJO run embedded in any Java program or container.

Randy Kahle
My impression of NetKernel, which granted may be out of date, is that it's primarily an implementation of the REST paradigm and architecture for building *any* system — not necessarily, and not particularly, web- or HTTP-related systems. While it may be excellent, it's also likely that the question is specifically about APIs for RESTful Web Development, specifically. So I'm not sure NetKernel is particularly relevant.
Avi Flax
Your impression is correct, NetKernel is a general purpose computing platform and is excellent for HTTP based systems.NetKernel 4 is a major update and includes new technologies such as the Grammar engine that supports bi-directional URI parsing and building based on an external grammar. That feature in particular makes building REST WS easy. And since an endpoint can be written in Java (etc) it seems reasonable to consider it along with Restlets, etc. NetKernel 4 is very small, can be booted up as a POJO/Container within e.g. Tomcat and can act as a REST WS endpoint manager.
Randy Kahle
+3  A: 

I'm a big fan of Restlet. At my firm we've successfully used both the server and client APIs extensively in multiple apps, which have performed well and been stable for the long term.

I've also been extremely satisfied with how well-run the project is, with a clear roadmap; an open, flexible, and effective development process; a solid community; and an emphasis on stability and strong support of current releases.

I haven't used Jersey so I can't really speak to it.

Also, it may be useful to point out that while Jersey itself has it's own API, that's not the API generally used for developing RESTful applications with Jersey. As stated on its home page, Jersey is the reference implementation of the JAX-RS API, which the upcoming Restlet 2.0 also implements.

Therefore, instead of choosing between Restlet and Jersey, a good choice might be to develop an application using the JAX-RS API. Your code would then be implementation-agnostic, and you could choose an implementation for actually running your application based on the deployment, support, and other runtime characteristics of the two implementations.

Again, I'm not all that familiar with Jersey, but I've been very pleased with the flexibility of Restlet. Restlet supports RESTful web services running as a standalone application, or inside a standard Servlet container. It's many extensions, and the ability to make your own, also enable it to integrate easily into an organization's existing software ecosystem.

Good luck!

Avi Flax
Are you using v 1.1.6 or v 2? Also, are you running Restlet in an app server or using their stand alone "Noelios Restlet Engine"?
Marcus
We're using mostly 1.1.x, and even a little 1.0 in some older apps we haven't upgraded yet. We'll move to 2.0 as soon as 2.0.1 is released!Our apps all run as standalone applications (using the Tanuki Java Service Wrapper), not in Servlet containers. I prefer the control and isolation that this approach affords.FYI, the NRE is the implementation of Restlet's own API. I'm pretty sure that any time one is using Restlet, one needs to use the NRE — even when running in a Servlet container. This is simpler with 2.0, where the API and the NRE are in the same JAR.
Avi Flax
A: 

I have used Jersey and am happy with it, but I am considering converting to the spring implementation because I have had issues with the Jersey/Spring integration, mainly with AOP.

Matthew Sowders
@Matthew - How to include Jersey libraries in the Java file where to keep them in the folders ??
Aruna
+15  A: 

I've built a project with RESTlet. Recently I've begun evaluating Jersey. Jersey is close enough to what I want to continue trying it. The prior project may keep RESTlet out of inertia, but had I to choose all over again I would go with Jersey or rolling my own.

Background

Where I work I selected RESTlet when building our first Java RESTful web service. RESTlet got the job done, but I found it it to be heavyweight and suffer from NIH.

Subsequently I prepared a hands-on workshop for my local JUG where I used Jersey. This wasn't enough experience to definitively say that it's better than RESTlet. However, my first impressions of Jersey are better than they were of RESTlet.

Re-inventing Servlets

With a name like RESTlet, the project could have gone a couple ways:

  • minimal servlet or servlet adapter from which to implement a RESTful service OR
  • complete replacement of the Servlet framework with a new web application framework geared around REST

The RESTlet creators believed the latter was the better choice. A consequence of this decision is that all the code inventing a new web app framework contributes to a large codebase, more dependencies, and more to understand when using RESTlet to build your service.

RESTlet does provide a Servlet. It's a bridge class that jettisons the Servlet API as quickly as possible.

Overly Deep and Java-ish API

If you think the Java Swing API is a great example of how to make a rich API then you probably disagree that this is a drawback for RESTlet. My bias is for less framework, less abstraction and less generality in a REST framework. Or at least an easier to use facade on top of your richly decomposed OO interface. Getting the value of query param called limit should not require this much code:

request.getResourceRef().getQueryAsForm().getFirstValue("limit")

Getting the value of URI template param is more straightforward. But the code above is symptomatic of a framework that reinvents instead of augments existing web frameworks.

Practice What You Preach

A couple of the benefits of REST are simplicity when compared with other architectural styles and that REST services work with the grain of the Web. Similarly a REST framework should be simple and should build on the prior art for building web apps in Java.

RESTlet fails on both marks.

Based on initial experience, Jersey scores better on simplicity. If JAX-RS succeeds as a standard, then by definition Jersey works within the grain of Java web apps. Even without that Jersey feels a bit more natural. Annotations are a good fit.

toolbear74
Newer versions of RESTlet implement JAX-RS. But software rarely gets less complicated over time. RESTlet + JAX-RS is all the weight of RESTlet plus a JAX-RS mapping.
toolbear74
Nicely explained answer +1
whatnick
Thanks for the good info +1
Jon
+1  A: 

I've used Jersey daily for 18 months and consider it to be the best news in Java web service development in the last few years. It's clean, works, and is a joy to program.

ae6rt