The Right Tool For the Job
I need to build a server!
So many choices
ASP.Net MVC
Rails CakeSinatra
Play Liberator Grails
Meteor
Code Ignitor
DjangoCompojure
Spring
Scalatra
What Makes Them Different?
• Language
• Performance
• General Developer Speed
• Library Support
• Abstraction
Protocol An established set of guidelines for
communication
Some Languages Have Nice Built in Web Server Support
var http = require("http"); http.createServer(function(request,response){ response.write("Hello World"); response.end(); }).listen(8080);
package main !import ( "fmt" "net/http" ) !func handler(w http.ResponseWriter, r *http.Request) { fmt.Fprint(w, "Hello, world!") } !func main() { http.HandleFunc("/", handler) http.ListenAndServe(":8080", nil) }
Ruby also has a built in server library….
… but no one uses it.
Rack wraps HTTP in a very thin Ruby layer
Rackapp = lambda do |env| body = "Hello, World!" [ 200, { "Content-Type" => "text/plain", "Content-Length" => body.length.to_s }, [body] ] end !run app
Let’s Make this Prettier
require 'sinatra' !
get '/' do "Hello World!" end
Sinatra
And The Next Step?
Well there are other alternatives, but let’s hold
off on those…
Let’s Compare, Shall We?
Why Would We Ever Use Rack?
With Great Power Comes…
With Great Power Comes…
So why does Sinatra give us?
DSL (Domain Specific
Language)
A bit of convenience
So why does Rails give us?
ActiveRecord ActiveSupport
ActionView
Rails and Sinatra are Popular!