Created
October 16, 2012 16:51
-
-
Save dphase/3900505 to your computer and use it in GitHub Desktop.
padrino/sinatra RESTful JSON example
This file contains 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
# --------------------------------------------------------------------- | |
# User Demographics | |
# --------------------------------------------------------------------- | |
get :user, :map => '/user', :with => :id, :provides => :json do | |
_user = Auth[:userid => params[:id]] | |
user = Hash.new | |
user[:userid] = _user.userid | |
user[:firstname] = _user.firstname | |
user[:lastname] = _user.lastname | |
user[:username] = _user.username | |
user.to_json | |
end | |
post :user, :map => '/user', :with => :id do | |
user = Auth[:userid => params[:id]] | |
json = JSON.parse(env['rack.input'].gets).symbolize_keys | |
user.update(json) | |
200 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment