RESTful using Spring Framework

I don’t need to say that RESTful web services are very popular this days. So, you need it, for sure, but what to choose? I’ve tried different Java frameworks for REST, most times it was Jersey and Spring MVC, and think that for most cases Spring is the best option for building RESTful applications using Java.

If you already have a Spring app, then you don’t need to make complex configuration to start implementing RESTful API with Spring. Just configure view resolver for JSON, and use standard annotations like:


Why groovy

For last projects i choose Groovy as a main programming language, where it’s possible. Why? Because i think it’s optimal solution for most of my projects.

It’s very pragmatic, agile, powerful and expressing language. You write less code that using Java, you don’t require to write all those “getters/setters”, wrappers, huge hierarchy of objects, etc.  If you know you can use some functional-kind tricks, so two hundred java code can be rewritten using few lines. And then it requires less time for refactor, for bugfixing, for code review, for understanding, etc, etc.

It also easy to start using it. Really. There a no learning curve. Basically it’s just plain Java with additional syntax sugar. So you can rename your *.java files to *.groovy, and, ta-da-dam, you are using Groovy :)  Maybe with some rare exceptions, but it works. And then, when you feel flavor of Groovy, you will start using its feautures. Event junior java developers can start using it after short introduction, i’ve tried to teach few juniors – just fine.

And also there are good documentation, very good IDE support (at least by IntelliJ IDEA) and by development tools (like Maven, code-coverage, etc).

JVM is my choice because i’m doing mostly server-side project, and there are no alternatives with such solid base. I has done some project using python and ruby, and even PHP and Perl, but don’t pleased of quality of libraries, development tools, etc. Of course I’ve spent some time on other languages for JVM. Scala, for example, can be good language, for some teams, but it have high learning curve, very chaotic infrastructure and syntax, and it’s too academic it think. Clojure is other good choice, i’ve used it for an small project (~8K SLOC), and can say that it’s cool, but it’s not solid, it’s too young, there are no tools and IDEs (only Emacs, but did you know any junior developer who want to use Emacs? :)), so it’s not ready for production use yet.

Main problem with Groovy that it’s slow language. But i have to say, that for last couple of years i worked on different datamining projects, and know that at leas 80% (sometimes 95%) of your time you spent on non critical code, on architecture, refactoring, etc. And using Groovy you can spent this time more effectively. And when you found an bottleneck – rewrite it using Java, if you wish. Or rewrite using C/C++. Or maybe assembler. But, you now, it’s always better to think more, and write more robust algorithm on high level. And most of libraries already written using plain Java, so it fast, of course not so fast as C, but faster that Groovy.