Restaurant serves RESTful API on Rails.
Restaurant provides controller-less & RESTful API. All controllers and routings will be auto-defined from your config/roles.yml definition.
# app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
include Restaurant::ControllerHelper
end
Doorkeeper is supported for authentication by default.
$ rails g doorkeeper:install
$ rails g doorkeeper:migration
$ rake db:migrate
# app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
doorkeeper_for :all
end
- User with "public" scope token
- can access /recipes/:id
- User with "admin" scope token
- can access /recipes/:id
- can access /recipes
- can filter recipes by id and title
- can sort recipes by id and title
# config/roles.yml
public:
recipes:
actions:
- show
admin:
recipes:
actions:
- index
- show
where:
- id
- title
order:
- id
- title
context "with where params" do
it "returns recipes filtered by given query" do
get "/recipes", { where: { title: { eq: recipe.title } } }, env
response.should be_ok
response.body.should be_json(
"body" => nil,
"created_at" => "2000-01-01T00:00:00Z",
"id" => 1,
"title" => "title 1",
"created_at" => "2000-01-01T00:00:00Z",
"user_id" => 1
)
end
end