TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

A Sinatra-inspired micro web framework for Java

121 pointsby codenutover 11 years ago

22 comments

pronover 11 years ago
This project is nice but it&#x27;s important to mention that there is actually a &quot;Java micro web framework&quot; standard called JAX-RS that is pretty widely adopted (with solid open-source implementations by JBoss, Apache, Oracle and others). Here&#x27;s a rather old comparison of JAX-RS implementations: <a href="http://www.infoq.com/news/2008/10/jaxrs-comparison" rel="nofollow">http:&#x2F;&#x2F;www.infoq.com&#x2F;news&#x2F;2008&#x2F;10&#x2F;jaxrs-comparison</a><p>Its most notable implementation is perhaps Jersey (<a href="https://jersey.java.net/documentation/latest/getting-started.html" rel="nofollow">https:&#x2F;&#x2F;jersey.java.net&#x2F;documentation&#x2F;latest&#x2F;getting-started...</a>), which is used, for example, by Dropwizard (mentioned in another comment).<p>Some of these implementations include important features like health and performance monitoring.
评论 #6373553 未加载
hawleyalover 11 years ago
Somehow having that much nesting and redundancy doesn&#x27;t fit the word &quot;micro&quot; or draw parallels with Sinatra.<p>Sinatra:<p><pre><code> get &#x27;&#x2F;hi&#x27; do &quot;Hello World!&quot; end </code></pre> Spark:<p><pre><code> public class HelloWorld { public static void main(String[] args) { get(new Route(&quot;&#x2F;hello&quot;) { @Override public Object handle(Request request, Response response) { return &quot;Hello World!&quot;; } }); } }</code></pre>
评论 #6373647 未加载
trailfoxover 11 years ago
Speaking of Sinatra-inspired web frameworks on the JVM have a look at Scalatra:<p><a href="http://scalatra.org/" rel="nofollow">http:&#x2F;&#x2F;scalatra.org&#x2F;</a><p><a href="https://github.com/scalatra/scalatra" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;scalatra&#x2F;scalatra</a>
评论 #6372659 未加载
评论 #6372681 未加载
评论 #6372689 未加载
6renover 11 years ago
I think it&#x27;s simpler to tribute Sinatra in Java by annotating methods:<p><pre><code> @get(&#x27;&#x2F;hi&#x27;) String myMethod() { return &quot;Hello World!&quot;; } </code></pre> I made a prototype of this (including extracting arguments Sinatra-style, which I think is its coolest bit), and didn&#x27;t encounter any serious problems with this approach.
评论 #6376717 未加载
drawkboxover 11 years ago
Definitely something that was needed, microframeworks are great. Restlet I used long ago but still very Java enterprisey. Play! is like Java&#x27;s Django&#x2F;Rails and now Spark is the Sinatra, simple and minimal. Scalatra mentioned here looks great as well, all these wonderful minimal Java toys.
habosaover 11 years ago
This is fantastic. I know a lot of programming languages and I love them all for different reasons, but I think I am most productive and most likely to produce error-free programs in Java. All the verbosity that people hate is a feature to me, I know exactly what my program is doing.<p>However, I have done 95% of my web development in Ruby due to the Sinatra and Rails frameworks. The developer experience is too good to ignore. I&#x27;m hoping this can replace my Sinatra use case ... I don&#x27;t think the magic of Rails could ever be replicated in Java.
stevvooeover 11 years ago
Where does this stand against dropwizard?
评论 #6372336 未加载
film42over 11 years ago
This looks really cool, I can&#x27;t wait to hack around with this!<p>Question for the community: I don&#x27;t have enough experience to know how this stacks up against other servers out there. Also, how do the people HN enjoy using java as a webserver (lang-wise, scaling-wise, etc)?<p>Any feedback would be much appreciated!!
评论 #6372369 未加载
评论 #6372476 未加载
评论 #6374630 未加载
评论 #6372322 未加载
评论 #6372451 未加载
ShabbyDooover 11 years ago
I had looked at Spark a couple of weeks ago. I&#x27;m looking for a lightweight service-y sort of framework which just happens to have a good HTTP service available out-of-the-box. My application does back-end processing and coordinates a bunch of data feeds, thick-client HTTP requests, background processing, etc. all together. Spark was too web-centric (not a bad thing, just not what I need). OSGi was an attempt to be what I want, but its requirement of classpath isolation (a good idea conceptually) is onerous in practice. Right now, I&#x27;m using a homespun amalgam of Grizzly, Guice, and java.util.concurrent (for thread pooling), and other stuff. I really didn&#x27;t want to build my own container. I&#x27;m intrigued by Apache Karaf, but OSGi is a huge pill to swallow (If you haven&#x27;t debugged OSGi classloading issues, you&#x27;d be in for a treat).<p>In a nutshell, I want a service lifecycle container which allows me to write small, lightweight, modular services which depend on each other. The container should provide for cross-cutting concerns like monitoring, management, configuration, logging, auditability (I have concrete definitions for these things -- they&#x27;re not just abstract biz-speak to me). HTTP should be an out-of-the-box, optional module. A service which exposes another service via a RESTful interface and depends upon the HTTP service should be another. For my application, services which listen to multicast data streams are just as important interfaces to the world as JSON-over-HTTP-via-REST. I want to write the HelloWorld method body and be able to do stuff like: expose it via a RESTful interface, invoke it every N seconds, inject an interface exposing the HelloWorld contract into other services, etc. When I want to know how my HelloWorld service is performing, there&#x27;s a pre-built web interface which provides New Relic-esque views. I&#x27;d like to capture audit trails of the transactional flows through my services from an origination point (HTTP call, scheduled job, etc.) so I can translate failures, poor performance, usage rates, etc. into meaningful information (I wrote a poor man&#x27;s version of this myself, and it&#x27;s been quite useful).<p>Does anything like this exist? I sure can&#x27;t find it. Modern JBoss (now Wildfly) might actually be closer to my requirements than I think. Perhaps I should look at the work they&#x27;re doing on Version 8.
评论 #6374345 未加载
评论 #6374496 未加载
评论 #6374942 未加载
msgilliganover 11 years ago
Ratpack Framework is a Sinatra-inspired framework for the JVM worth noting: <a href="http://www.ratpack-framework.org" rel="nofollow">http:&#x2F;&#x2F;www.ratpack-framework.org</a><p>Groovy:<p><pre><code> ratpack { handlers { get(&#x27;hello&#x27;) { response.send &quot;Hello world!&quot; } } } </code></pre> It can also be used (with somewhat less brevity) in good, old-fashioned Java.<p>An 0.9.0 release is expected in a few weeks and the project is undergoing rapid (and sometimes API-changing) development, but it looks very promising.
nahnameover 11 years ago
Have people dropped the &#x27;com&#x27; from java projects now? Not arguing in favor, the whole thing is ridiculous to me (src&#x2F;main&#x2F;com&#x2F;actual_files). Just curious.
评论 #6372578 未加载
评论 #6372378 未加载
scorchinover 11 years ago
There&#x27;s also webbit-rest: <a href="https://github.com/webbit/webbit-rest" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;webbit&#x2F;webbit-rest</a>
Zolomonover 11 years ago
I wrote a semi-realtime implementation of the planning poker estimation technique at [1] using Spark and some template engine I found.<p>This was for a course in software project management with some time restraints, so only focused on getting it done.<p>[1] <a href="https://github.com/Zolomon/PlanningPoker" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;Zolomon&#x2F;PlanningPoker</a>
bhauerover 11 years ago
For what it&#x27;s worth, Spark performs quite well in terms of request routing when compared to other JVM frameworks of various sizes [1].<p>[1] <a href="http://www.techempower.com/benchmarks/#section=data-r6&amp;hw=ec2&amp;test=json&amp;l=6g4" rel="nofollow">http:&#x2F;&#x2F;www.techempower.com&#x2F;benchmarks&#x2F;#section=data-r6&amp;hw=ec...</a>
kitdover 11 years ago
Very nice! Had a look at this a year or so ago and it would be a great base for mocking up backends IMHO.<p>In a similar vein is Google SiteBricks: <a href="http://sitebricks.org/#home" rel="nofollow">http:&#x2F;&#x2F;sitebricks.org&#x2F;#home</a><p>Slightly heavier weight but with more features (templating, annotations, etc). Depends on Guice.
chotachetanover 11 years ago
It is a nice one. I use Jelastic(www.jelastic.com) for my startup. What if we can have the same functionality there integrated. But this is needed at least the microframeworks are nice. Thinking that the same kind of thing can be also achieved with he framework integration in Jelastic.
Oculusover 11 years ago
Finally a web framework I can use. All the Java web frameworks I tried to use are way too enterprise-y.
评论 #6373842 未加载
Shankover 11 years ago
It really bugs me that they decided to clone the Sinatra README page, keeping most of the docs on one giant list instead of a more traditional multi-page doc approach. See here: <a href="http://www.sparkjava.com/readme.html" rel="nofollow">http:&#x2F;&#x2F;www.sparkjava.com&#x2F;readme.html</a><p>In addition, some of their docs link to a Google Code page, which keeps some examples on its index too: <a href="https://code.google.com/p/spark-java/" rel="nofollow">https:&#x2F;&#x2F;code.google.com&#x2F;p&#x2F;spark-java&#x2F;</a><p>Lastly, it appears they&#x27;re using GitHub for actual code, and, while they have a Github wiki created, it has no information.<p>I wish I could stress just how important it is to have all of the docs in one centralized location. Somewhere along the line, one of the five places they have examples will get out of date, and it&#x27;ll be difficult to play spot the differences when it&#x27;s replicated everywhere.
matt__ringover 11 years ago
I love it! Just whipped up a couple of toy web services in 15 mins using Spark. They will be part of a technical interview coding task.<p>True, Spark may not be better&#x2F;more concise than JAX-RS, but fun to try anyway.
f4stjackover 11 years ago
Okay. I am holding the idiot ball here: How can we deploy an app developed with spark? What are our options? Heroku? AWS? I haven&#x27;t seen anything regarding to deployment in the documentation.
评论 #6373546 未加载
评论 #6373594 未加载
评论 #6373562 未加载
rubiquityover 11 years ago
I feel like Keurig would be a no brainer as a name for a Java micro Web framework.
waffenklangover 11 years ago
would love to see such a mf for c&#x2F;c++...
评论 #6376685 未加载