Skip to content

Commit

Permalink
API GET /purr endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Chew committed Sep 17, 2020
1 parent aa81343 commit 544a27b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/controllers/api_controller.rb
@@ -1,2 +1,8 @@
class ApiController < ApplicationController
include Response

def random_image
image = Image.order(Arel.sql('RAND()')).first
json_response image, 200
end
end
5 changes: 5 additions & 0 deletions app/controllers/concerns/response.rb
@@ -0,0 +1,5 @@
module Response
def json_response(object, status = :ok)
render json: object, status: status
end
end
2 changes: 2 additions & 0 deletions app/models/Image.rb
@@ -0,0 +1,2 @@
class Image < ApplicationRecord
end
1 change: 1 addition & 0 deletions config/routes.rb
@@ -1,3 +1,4 @@
Rails.application.routes.draw do
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
get 'purr', to: 'api#random_image'
end

0 comments on commit 544a27b

Please sign in to comment.