Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to choose the perfect RESTful framework?

I know this question is too wide to be answered with a simple "use this framework", but I would really appreciate your advice on that one.

I'm looking to make a (quite complex) project than will run over an API. I'm open to any programming language (PHP, Python, Java mostly) and found many frameworks that are more oriented to make a RESTful web server.

The only major constraint I have is that I would have a reusable, simple and not-code-spaghetti independent package in order to improve my API later easily or even switch to an other framework with no pain.

For Python & Java, I thought about making a dedicated package. Each action would call the dedicated method in the package, the package would return object/dict and the action would transform it to the proper format.

After many research, I hesitate between two framework that could be good for my work but I need your advice because I wouldn't make any mistakes here.

  1. Play! Framework (Java)
    • Pros :
      • Router are RESTFul oriented (you define the method (GET, POST, etc), the request and the class.method to use)
      • You don't have to make one class per action
    • Cons :
      • The Model is already included. If I later change the framework, maybe I will be stuck with it (but apparently not since Play! seems to use JPA)
      • Maybe the fact that if I want to send parameters to the action that would be defined in the method signature, I have to adopt the ClassName.properties instead of a json like {ClassName: {properties: 'value'}}
  2. Tornado Web (Python)
    • Pros :
      • Seems to be very powerful : used by FriendFeed (at least) !
      • Auth via major OpenId, OAuth and Facebook already implemented
      • Very light (could be a problem)
    • Cons :
      • Not so popular : you understand better the work by going into the code than the doc
      • Urls seems to be very basics (As far as I saw it, you have to define all the urls in one file, with all the class included)
      • One Class per action (that could be heavy)
      • Decorators for the basic (testing if user is auth, etc) must be made

For using them in production, it would be easily possible with apache & mod_proxy or nginx.

So, my questions is quite simple : what would you choose (between those two or others, I'm not closed to suggestions) and why ?

Thank you really much for your advice!

like image 330
Cyril N. Avatar asked Dec 08 '10 09:12

Cyril N.


1 Answers

My favorite RESTful Web App development framework is Restlet. It's a Java framework/library (it can be thought of as either) but it works well with Jython and JRuby, so if you prefer those languages you could still use it. I mostly use it with Groovy.

I prefer Restlet because:

  • Its API fully embraces and aligns with RESTful paradigms, so it encourages you to work RESTfully. For example, when a Router routes a request to a ServerResource, it creates a new instance of the ServerResource for every request. This encourages the implementation to be stateless. And there's a rich class hierarchy with all the concepts required to implement a RESTful web app: Client, Server, Protocol, VirtualHost, Request, Response, MediaType, Status, etc.

  • Its API includes classes for writing both servers and clients, and they're very consistent and almost symmetrical. For example, there's a ServerResource class and a ClientResource class. ServerResource.get() and ClientResource.get() both return a Representation. The only difference is that you implement ServerResource.get() and generate a response representation, while you call ClientResource.get() and receive a response representation.

  • The API is consistent with Java conventions. For example, if a request made with ClientResource.get() receives an error response such as 401, a ResourceException will be thrown. And if you're implementing a ServerResource and want to return an error status, you just throw a ResourceException (which is a RuntimeException, which is nice).

  • Via its extension mechanism, it plays very nicely with a broad array of the best Java libraries around. Extensions are included for various HTTP client and server libraries, databases, templating libraries, security libs, data libs such as XML, JSON, OAuth, OData, etc., and even OSGI.

  • Deployment is very flexible. You can embed a Restlet-powered API in an existing Java app, an existing Java Servlet app, or any standard Java Web App (Servlet) server. Or you can build a stand-alone server app with an embedded HTTP server such as Jetty — that's my preferred approach. And because it runs on the JVM, it runs on almost any hardware or OS.

  • It's mature, reliable, responsibly maintained, steadily improving, and well supported both by the community and commercially.

  • It's open source, and has very clear and well-structured code. The developers are happy to accept any contributions. I've submitted a few patches and had them committed to trunk quickly with no drama.

Other options I'd suggest would be the Python microframework Bottle and the Ruby microframework Sinatra. They're both simple, straightforward, lightweight, and effective. And because they work with the WSGI and Rack stacks, there's a rich set of "middleware" modules which can easily be used with them.

like image 118
Avi Flax Avatar answered Oct 25 '22 22:10

Avi Flax