{"id":1679,"date":"2014-09-15T07:03:25","date_gmt":"2014-09-15T13:03:25","guid":{"rendered":"http:\/\/www.mooreds.com\/wordpress\/?p=1679"},"modified":"2014-08-29T07:13:53","modified_gmt":"2014-08-29T13:13:53","slug":"java-rest-api-framework-options","status":"publish","type":"post","link":"https:\/\/www.mooreds.com\/wordpress\/archives\/1679","title":{"rendered":"Java REST API Framework Options"},"content":{"rendered":"<figure style=\"width: 240px\" class=\"wp-caption alignleft\"><img decoding=\"async\" class=\"alignleft\" title=\"rest by shioshvili\" src=\"http:\/\/www.mooreds.com\/wordpress\/wp-content\/uploads\/2014\/08\/234727120_f9353c20cf_m_resting.jpg\" alt=\"resting photo\" width=\"240\" \/><figcaption class=\"wp-caption-text\"><small>Photo by <a href=\"http:\/\/www.flickr.com\/photos\/70601645@N00\/234727120\" target=\"_blank\">shioshvili<\/a> <a title=\"Attribution-ShareAlike License\" href=\"http:\/\/creativecommons.org\/licenses\/by-sa\/2.0\/\" target=\"_blank\" rel=\"nofollow\"><img decoding=\"async\" src=\"http:\/\/www.mooreds.com\/wordpress\/wp-content\/plugins\/wp-inject\/images\/cc.png\" alt=\"\" \/><\/a><\/small><\/figcaption><\/figure>\n<p>I&#8217;ve been working with a couple of REST API solutions that exist in the Java tech stack.\u00a0 I haven&#8217;t seen any great analysis of REST API solutions (though Matt Raible does mention some in <a href=\"http:\/\/static.raibledesigns.com\/repository\/presentations\/Comparing_JVM_Web_Frameworks_February2014.pdf\">this exhaustive slide deck about Java frameworks<\/a> [pdf]), so wanted to share my on the ground experience.<\/p>\n<p>First up is <a href=\"http:\/\/restsql.org\/\">restSQL<\/a>.\u00a0 This framework makes it easy to get data from a database to a JSON or XML REST API and back.\u00a0 If you have a servlet container available, you write two configuration files, one with a SQL query and one with db connection information, and you have a RESTful API.\u00a0 For prototyping and database access, it is hard to beat.<\/p>\n<p>Pros:<\/p>\n<ul>\n<li>Quick to set up<\/li>\n<li>Only SQL knowledge is required<\/li>\n<li>No programming required<\/li>\n<li>Allows simple mapping of db table to resource, but can include one to one and one to many mappings<\/li>\n<li>Supports all four REST operations out of the box<\/li>\n<li>Supports XML as well as JSON<\/li>\n<li>Is an embeddable java library as well as a standalone framework<\/li>\n<li>Project maintainer is engaged and the project is moving forward<\/li>\n<\/ul>\n<p>Cons:<\/p>\n<ul>\n<li>Requires a servlet engine, and you have to restart it for changes to your configuration to be picked up<\/li>\n<li>Output format has limited customization<\/li>\n<li>Only works with mysql and postgresql databases (though there is some experimental support for <a href=\"https:\/\/github.com\/restsql\/restsql\/issues\/53\">Oracle<\/a> and <a href=\"https:\/\/github.com\/restsql\/restsql\/issues\/49\">MS SQL<\/a>)<\/li>\n<li>Doesn&#8217;t work with views<\/li>\n<li><a href=\"http:\/\/restsql.org\/doc\/Security.html\">The security model<\/a>, while fine grained, isn&#8217;t modern\/OAuth (can be solved with an API gateway (like <a href=\"http:\/\/www.3scale.net\/\">3scale<\/a>, <a href=\"http:\/\/tyk.io\/\">Tyk<\/a> or <a href=\"http:\/\/apiaxle.com\/\">ApiAxle<\/a>) or proxy<\/li>\n<\/ul>\n<p>The next framework I have experience with is <a href=\"http:\/\/dropwizard.io\/\">Dropwizard<\/a>.\u00a0 This is a powerful framework that creates uberjars that you can run on any port as a standalone service.\u00a0 It&#8217;s not limited to providing a JSON representation of database tables&#8211;if you can create a Java object, Dropwizard can serve it up as a JSON resource.<\/p>\n<p>Pros:<\/p>\n<ul>\n<li>Community support<\/li>\n<li>Extreme output formatting flexibility, but be prepared to write a <a href=\"http:\/\/fasterxml.github.io\/jackson-databind\/javadoc\/2.0.0\/com\/fasterxml\/jackson\/databind\/JsonDeserializer.html\">custom deserializer<\/a> if you want to handle anything other than reads of custom formatted objects<\/li>\n<li>Supports any database that hibernate supports<\/li>\n<li>Built in testing support<\/li>\n<li>Brings together &#8216;best of breed&#8217; tools like Jersey, Jackson and Hibernate, so you don&#8217;t have to do the integration yourself<\/li>\n<li>Great documentation<\/li>\n<\/ul>\n<p>Cons:<\/p>\n<ul>\n<li>Have to roll your own deployment solution (tarball, chef, puppet)<\/li>\n<li>No services startup script provided<\/li>\n<li><a href=\"http:\/\/maven.apache.org\/plugins\/maven-shade-plugin\/\">Shading<\/a> can slow down development<\/li>\n<li>Not yet at 1.0 release<\/li>\n<\/ul>\n<p>The last one I don&#8217;t have familiarity with, but a colleague used it in the past.\u00a0 It is <a href=\"http:\/\/www.sparkjava.com\/\">Sparkjava<\/a>.\u00a0 This is a lightweight framework that fits when you have an existing Java library with functionality you want to expose.\u00a0 I&#8217;m not competent to write pros\/cons for this framework, but wanted to mention it.<\/p>\n<p>The gorilla in the room that I haven&#8217;t had experience with (in terms of writing RESTful webs services) is <a href=\"http:\/\/spring.io\/guides\/gs\/rest-service\/\">Spring<\/a>.\u00a0 I would definitely include this in any greenfield solutions review.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been working with a couple of REST API solutions that exist in the Java tech stack.\u00a0 I haven&#8217;t seen any great analysis of REST API solutions (though Matt Raible [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[62,13,5],"tags":[],"class_list":["post-1679","post","type-post","status-publish","format-standard","hentry","category-apis","category-databases","category-java"],"_links":{"self":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts\/1679","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/comments?post=1679"}],"version-history":[{"count":2,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts\/1679\/revisions"}],"predecessor-version":[{"id":1682,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts\/1679\/revisions\/1682"}],"wp:attachment":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/media?parent=1679"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/categories?post=1679"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/tags?post=1679"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}