Last active
April 7, 2016 09:40
-
-
Save LolWalid/917c33acd2ff182508e30f7b3a592e32 to your computer and use it in GitHub Desktop.
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
| 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 |
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
| module API | |
| module V1 | |
| class MyController < API::V1::ApplicationController | |
| respond_to :json | |
| def method | |
| render json: { status: 200 } | |
| end | |
| end | |
| end | |
| end |
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
| 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