Rails5のAPIモードを試してみる

準備

$ ruby -v
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin13]
$ rails -v
Rails 5.0.0.1

new && bundle install

rails new hoge --api -T -B -d mysql
bundle install --path=vendor/bundle

middleware

$ rails middleware
use Rack::Sendfile
use ActionDispatch::Static
use ActionDispatch::Executor
use ActiveSupport::Cache::Strategy::LocalCache::Middleware
use Rack::Runtime
use ActionDispatch::RequestId
use Rails::Rack::Logger
use ActionDispatch::ShowExceptions
use ActionDispatch::DebugExceptions
use ActionDispatch::RemoteIp
use ActionDispatch::Reloader
use ActionDispatch::Callbacks
use ActiveRecord::Migration::CheckPending
use Rack::Head
use Rack::ConditionalGet
use Rack::ETag
run XXXX::Application.routes

※削りたければconfig.middleware.delete ::Rack::Sendfile等で削れるようです。

database.ymlのuser, passwordを設定

CREATE USER 'hoge'@'localhost' IDENTIFIED WITH mysql_native_password BY 'hoge';
UPDATE MYSQL.USER SET xxxx_priv = 'y' WHERE USER = 'hoge';

各種作成

rails g scaffold user
rails db:create

参考

http://edgeguides.rubyonrails.org/api_app.html