Skip to content

Instantly share code, notes, and snippets.

@sebglazebrook
Last active May 11, 2017 12:05
Show Gist options
  • Save sebglazebrook/e28e1af2ae881560b629030124913304 to your computer and use it in GitHub Desktop.
Save sebglazebrook/e28e1af2ae881560b629030124913304 to your computer and use it in GitHub Desktop.
# This is similar to a controller in rails
# each method represents a verb/action from rest
class User < Resource
include JsonRendering
def options
end
def head
end
def get(params = {})
# do whatever you want here we
# entirely up to the user
json_render UserRepo.all
end
def get_by_id(id, params = {})
# do whatever you want here we
# entirely up to the user
json_render UserRepo.find_by_id(id)
end
def post(id, params = {})
end
def put(id, params = {})
end
def patch(id, params = {})
end
def delete(id, params = {})
end
end
# this is similar to the routes.rb file in rails
class Router < ResourceRouter
route :users, at: "/people"
route :posts do
route :comments, only: [:get]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment