Restaurant serves your data via auto-defined RESTful API on your rails application.
# Gemfile
gem "restaurant"
# app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
include Restaurant::ControllerHelper
end
# config/routes.rb
Rails.application.routes.draw do
Restaurant::Router.route(self)
end
$ bundle install
$ bundle exec rails g doorkeeper:install
$ bundle exec rails g doorkeeper:migration
$ bundle exec rake db:migrate
Controllers and routes are auto-defined from your config/restaurant.yml. You can restrict requests by scopes, actions, attributes, and queries.
# config/restaurant.yml
public: # User with "public" scope token
recipes: #
actions: #
- show # can access to /recipes/:id
attributes: #
- title # can read recipe.title
admin: # User with "admin" scope token
recipes: #
actions: #
- index # can access to /recipes
- show # can access to /recipes/:id
where: #
- id # can filter recipes by id
- title # can filter recipes by title
order: #
- id # can sort recipes by id
- title # can sort recipes by title
attributes: #
- id # can read recipe.id
- title # can read recipe.title
SQL-like URI query system is supported.
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(
"id" => 1,
"user_id" => 1
"body" => "body 1",
"title" => "title 1",
"updated_at" => "2000-01-01T00:00:00Z",
"created_at" => "2000-01-01T00:00:00Z",
)
end
end