Created
September 4, 2012 07:48
-
-
Save coderdan/3618127 to your computer and use it in GitHub Desktop.
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
class CustomerAPI < Grape::API | |
version 'v1', :using => :header | |
rescue_from ActiveRecord::RecordInvalid do |e| | |
# Precondition Failed | |
error_response(:status => 412, :message => { :error => e.message }.to_json) | |
end | |
helpers do | |
def authenticate! | |
error!('Unauthorized', 401) unless env['HTTP_AUTHORIZATION'] == 'letmein' | |
end | |
end | |
resource :users do | |
before { authenticate! } | |
desc "Create a user" | |
post :create do | |
User.create!(params[:user]).to_json | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment