Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
168 lines (117 sloc) 5.05 KB


Step is a tiny Scala web framework inspired by Sinatra and originally based on some code I found on an awesome blog post.

It could probably use a lot of work; it's my first Scala project. I welcome comments, pull requests, and issues.


package com.thinkminimo.step

class StepExample extends Step {

  // send a text/html content type back each time
  before {
    contentType = "text/html"

  // parse matching requests, saving things prefixed with ':' as params
  get("/date/:year/:month/:day") {
      <li>Year: {params(":year")}</li>
      <li>Month: {params(":month")}</li>
      <li>Day: {params(":day")}</li>

  // produce a simple HTML form
  get("/form") {
    <form action='/post' method='POST'>
      Post something: <input name='submission' type='text'/>
      <input type='submit'/>

  // handle POSTs from the form generated above
  post("/post") {
    <h1>You posted: {params("submission")}</h1>

  // respond to '/' with a greeting
  get("/") {
    <h1>Hello world!</h1>

  // send redirect headers
  get("/see_ya") {

  // set a session var
  get("/set/:session_val") {
    session("val") = params("session_val")
    <h1>Session var set</h1>

  // see session var
  get("/see") {
    session("val") match {
      case Some(v:String) => v
      case _ => "No session var set"

Quick Start

  1. Install Java
You'll need Java installed; I have it running with 1.5
  1. Install simple-build-tool
Step uses sbt, a fantastic tool for building Scala programs.  For instructions, see [the sbt site](
  1. Run sbt
In the directory you downloaded step to, run `sbt`.
sbt will download core dependencies, and Scala itself if it needs to.
  1. Download dependencies
At the sbt prompt, type `update`.  This will download required dependencies.
  1. Try it out
At the sbt prompt, type `jetty-run`.  This will run step with the example servlet on port 8080.
  1. Navigate to http://localhost:8080
You should see "Hello world."  You can poke around the example code in src/main/scala/StepExample.scala
to see what's going on.

Supported Methods

  • before

    Run some block before a request is returned.

  • get(path)

    Respond to a GET request.

    Specify the route to match, with parameters to store prefixed with : like Sinatra. "/match/this/path/and/save/:this" would match that GET request, and provide you with a params(":this") in your block.

  • post(path)

    Respond to a POST request.

    Posted variables are available in the params hash.

  • delete(path)

    Respond to a DELETE request.

  • put(path)

    Respond to a PUT request.


Session support has recently been added. To see how to use sessions in your Step apps, check out the test servlet, at src/test/scala/StepTest.scala

Testing Your Step Applications

Step includes StepSuite - a framework for writing the suite of tests for your Step application. It's an extension of FunSuite with some utility functions to request your app for responses and referring the responses in ease. Here's an example of StepSuite.

class TheStepAppTests extends StepSuite with ShouldMatchers {
  // `TheStepApp` is your app which extends Step
  route(classOf[TheStepApp], "/*")

  test("simple get") {
    get("/path/to/something") {
      status should equal (200)
      body should include ("hi!")

It supports HTTP GET/POST tests with or without request parameters and sessions. Referring StepSuiteTest.scala would be helpful to understand tests with StepSuite.

Testing Step

A test suite can be found in src/test/scala. Inside StepTest.scala is a small testing servlet along with some assertions. If you've made changes to Step itself and you'd like to make sure that this testing servlet still works, you can type test at the sbt prompt.


While Step can be run standalone for testing and meddling, you can also package it up in a .jar for use in other projects. At the sbt prompt, type package. Step's only dependency is a recent version of the servlet API. For more information, see the sbt site


I'd like to thank Gabriele Renzi for the inspirational blog post and continual help, and Mark Harrah for help on the sbt mailing list and for creating sbt. Ant+Ivy by itself was a total bitch.

I'd also like to thank Yusuke Kuoka for adding sessions and header support.


  • more tests
  • 'splat' support ala Sinatra?