Skip to content

Instantly share code, notes, and snippets.

@LolWalid
Last active April 7, 2016 09:40
Show Gist options
  • Select an option

  • Save LolWalid/917c33acd2ff182508e30f7b3a592e32 to your computer and use it in GitHub Desktop.

Select an option

Save LolWalid/917c33acd2ff182508e30f7b3a592e32 to your computer and use it in GitHub Desktop.
module API
module V1
class ApplicationController < ActionController::Base
before_filter :authenticate
TOKEN = ENV['my_api_token'].freeze
protected
def authenticate
authenticate_or_request_with_http_token do |token, _|
token == TOKEN
end
end
end
end
end
module API
module V1
class MyController < API::V1::ApplicationController
respond_to :json
def method
render json: { status: 200 }
end
end
end
end
curl -X GET http://localhost:3001/api/my_controller/method -H 'Authorization: Token token="123a"'
curl -X POST http://localhost:3001/api/my_controller/method -H 'Authorization: Token token="123a"' -d { key: 'value' }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment