Coder Social home page Coder Social logo

step's Introduction

About

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.

Example

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") {
    <ul>
      <li>Year: {params("year")}</li>
      <li>Month: {params("month")}</li>
      <li>Day: {params("day")}</li>
    </ul>
  }

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

  // 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>
  }
}

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](http://code.google.com/p/simple-build-tool/wiki/Setup)
  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 the Servlet API and Jetty.
  1. Try it out
At the sbt prompt, type `jetty-run`.  This will run step with the example 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

    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

    Respond to a POST request.

    Posted variables are available in the params hash.

  • delete

    Respond to a DELETE request.

  • put

    Respond to a PUT request.

Miscellaneous

While Step can be run standalone, you can also package it up in a .jar for use in other projects. At the sbt prompt, type package. For more information, see the sbt site

Props

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

Todo

  • tests
  • docs
  • more tests
  • regex and 'splat' support ala Sinatra?

step's People

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.