Created
November 30, 2011 05:51
-
-
Save andynu/1408208 to your computer and use it in GitHub Desktop.
Bare bones, no auth, json rest server in rails.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -x | |
rvm install 1.9.3-head | |
rvm use 1.9.3-head | |
rvm gemset create rails31 | |
rvm use 1.9.3-head@rails31 | |
gem install bundler rails | |
rails new rest_api | |
cd rest_api | |
git init . | |
git add . | |
git commit -a -m'vanilla rails' | |
echo rvm use 1.9.3-head@rails31 > .rvmrc | |
rvm rvmrc trust . | |
rails generate model Reservation id:integer name:string date:datetime | |
rake db:create | |
rake db:migrate | |
git add . | |
git commit -a -m'reservation model' | |
rails generate controller Reservations | |
git add . | |
git commit -a -m'vanilla reservations controller' | |
echo "gem 'inherited_resources'" >> Gemfile | |
echo "gem 'responders' >> Gemfile" | |
bundle install | |
echo "class ReservationsController < InheritedResources::Base | |
respond_to :html, :xml, :json | |
end" > app/controllers/reservations_controller.rb | |
echo "RestApi::Application.routes.draw do | |
resource :reservations | |
end" > config/routes.rb | |
git commit -a -m'wire up the inherited_resources and routes' | |
rails server 2>&1 1>/dev/null & | |
echo "wait for server" | |
sleep 10 | |
curl -d "{id: 1, name:'Dinner', date:'Tue Nov 29 2011 23:55:16 GMT-0500 (EST)'}" http://localhost:3000/reservations.json | |
# {"created_at":"2011-11-30T04:56:36Z","date":null,"id":1,"name":null,"updated_at":"2011-11-30T04:56:36Z"} | |
curl "http://localhost:3000/reservations.json?id=1" | |
# {"created_at":"2011-11-30T04:56:36Z","date":null,"id":1,"name":null,"updated_at":"2011-11-30T04:56:36Z"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment