Skip to content

Instantly share code, notes, and snippets.

@alandipert
Created April 27, 2009 23:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alandipert/102817 to your computer and use it in GitHub Desktop.
Save alandipert/102817 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'sinatra'
require 'json'
class Person
attr_accessor :first, :last
def initialize(first, last)
@first = first
@last = last
end
def to_json
["first" => @first, "last" => @last].to_json
end
end
people = [
Person.new('Alan', 'Dipert'),
Person.new('Micha', 'Niskin'),
Person.new('Oren', 'Niskin'),
Person.new('Albert', 'Einstein')
]
before do
content_type 'text/json'
end
put '/person/:id/' do
id = params[:id].to_i
people[id].first = params[:first]
people[id].last = params[:last]
people[id].to_json
end
get '/person/:id/' do
people[params[:id].to_i].to_json
end
get '/person/' do
people.to_json
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment