

Sinatra clone in Scala - wooby
http://github.com/alandipert/step/tree/master

======
10ren
Is the whole thing really just the one file (110 lines)?
[http://github.com/alandipert/step/blob/42cee9ecd360205def359...](http://github.com/alandipert/step/blob/42cee9ecd360205def359ce2719f34120edee499/src/main/scala/Step.scala)
I know it describes itself as "tiny", and sinatra is also tiny, but that
seems... small. (I don't know anything about Scala - is it especially
concise?)

I like how the HTML seems to be a first-class datatype in the example (is that
a Scala thing? I'd better do some research):

    
    
        get("/date/:year/:month/:day") {
          <ul>
            <li>Year: {params("year")}</li>
            <li>Month: {params("month")}</li>
            <li>Day: {params("day")}</li>
          </ul>
      }

~~~
wooby
Yeah it's pretty small. With Scala you basically get free HTML templating
because of XML literal support. It's missing a lot of Sinatra stuff though:
'splat' and regex URI pattern matching, file uploads, sessions...

~~~
vladev
Maybe leveraging pattern matching could improve.

Actually - we can be able to implement our own methods get(), post(), etc. via
pattern matching... So inspiring - on my way to fork it. ;)

------
rmaccloy
Awesome. I actually fired up Sinatra on JRuby for a micro-app that needs to
talk to some Java stuff last week. All of the existing stuff in Scala was way
too heavy for the purpose. (Clojure/compojure has comparable overhead to
Sinatra assuming you're familiar with Clojure, but it was untenable in this
particular circumstance.)

At least half the magic of Sinatra is that you can write a single Ruby script,
exec it and not have to fool around with build/generate/scaffold script or web
server configuration to get something useful. It seems like you're pretty
close, given that Java has no standard dependency retrieval system.

------
caustic
Amazing conciseness. Don't forget to check out lift web framework
<http://liftweb.net/>. It's written in Scala too and uses similar techniques.

------
papaf
Very cool. I notice that you're using sbt to build. I'm using maven to build a
scala project. I'd be very interested to know how sbt compares to maven if you
have experience with both build systems.

~~~
wooby
I haven't used maven (the first version of this thing used ant+ivy), but it
was pretty messy compared to what I have going now. I'd say if you have the
luxury of working with a Scala-only project, sbt is definitely the way to go.

------
holaberlin
It looks like there is no separation between view and controller. Mixing HTML
into your controller methods seems like a step backwards.

~~~
wastedbrains
If this is a port of Sinatra that is an option to make a very small concise
webservice. You can choose to do seperation, but if you want something very
simple and compact a single file can be easier. We have a Sinatra app that has
the model,view,controller, and tests in a single file that is less than 250
LOC. It would be more obfuscated to have 5 files of less than 50 LOC each
(Some with as little as 4 lines).

If it doesn't provide any option for separation that is bad, but for micro
services it can be really nice.

~~~
wooby
For sure. I'm just using XML literals in the example because it looks cool.
But I'm also using this for a client job, and it's producing JSON.

It's not nearly as powerful as the real Sinatra, but it saves me the
shenanigans of warbling Sinatra apps for servlet deployment.

