Created
July 3, 2014 03:49
-
-
Save cthornton/10378c63ef13a6dc2bb2 to your computer and use it in GitHub Desktop.
Dry your JSON API - What it probably looks like
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 PostsController < ActionController::Base | |
def index | |
@user = User.find_by(api_key: request.authorization) | |
if !@user | |
return render json: {error: 'invalid api key'}, status: :unauthorized | |
end | |
@posts = @user.posts | |
# ... render JSON | |
end | |
def show | |
@user = User.find_by(api_key: request.authorization) | |
# ... validate user | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment