Skip to content

Instantly share code, notes, and snippets.

@hodak
Created April 10, 2015 07:50
Show Gist options
  • Save hodak/581743fc401ae6be7736 to your computer and use it in GitHub Desktop.
Save hodak/581743fc401ae6be7736 to your computer and use it in GitHub Desktop.
Structuring simple API responses
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