Created
April 10, 2015 07:50
-
-
Save hodak/581743fc401ae6be7736 to your computer and use it in GitHub Desktop.
Structuring simple API responses
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
module API | |
class UsersController | |
# This will cause problems in exactly two years from now | |
def index | |
render json: User.all | |
end | |
# Writing it this way from the beginning will allow | |
# to extend this object when the requirements change | |
def index | |
render json: { users: User.all } | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment