Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Rails::API

 Rails::API

Rails::API の紹介記事です。Rails 5.0.0.beta3 でのベンチマーク付き。

Shinichi Maeshima

March 01, 2016
Tweet

More Decks by Shinichi Maeshima

Other Decks in Technology

Transcript

  1. WHAT’S RAILS::API? ▸ gem ▸ merged with Rails 5.0 ▸

    Rails ͔Β API αʔόʹෆཁͳ΋ͷΛলུ ▸ Cookies ▸ Flash ▸ Session ▸ etc
  2. HOW TO CREATE? ▸ new application ▸ rails new yourapp

    —api ▸ existing application ▸ http://edgeguides.rubyonrails.org/ api_app.html#changing-an-existing-application
  3. use Rack::Sendfile use ActionDispatch::LoadInterlock use ActiveSupport::Cache::Strategy::LocalCache::Middleware use Rack::Runtime use Rack::MethodOverride

    use ActionDispatch::RequestId use Rails::Rack::Logger use ActionDispatch::ShowExceptions use ActionDispatch::DebugExceptions use ActionDispatch::RemoteIp use ActionDispatch::Callbacks use ActiveRecord::ConnectionAdapters::ConnectionManagement use ActiveRecord::QueryCache use ActionDispatch::Cookies use ActionDispatch::Session::CookieStore use ActionDispatch::Flash use Rack::Head use Rack::ConditionalGet use Rack::ETag run RailsWebSample::Application.routes RAILS_ENV=production rails middleware web
  4. use Rack::Sendfile use ActionDispatch::LoadInterlock 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::Callbacks use ActiveRecord::ConnectionAdapters::ConnectionManagement use ActiveRecord::QueryCache use Rack::Head use Rack::ConditionalGet use Rack::ETag run RailsApiSample::Application.routes RAILS_ENV=production rails middleware api
  5. AbstractController::Rendering, AbstractController::Translation, AbstractController::AssetPaths, Helpers, UrlFor, Redirecting, ActionView::Layouts, Rendering, Renderers::All, ConditionalGet,

    EtagWithTemplateDigest, Caching, MimeResponds, ImplicitRender, StrongParameters, ActionController::Base::MODULES web Cookies, Flash, FormBuilder, RequestForgeryProtection, ForceSSL, Streaming, DataStreaming, HttpAuthentication::Basic::ControllerMethods, HttpAuthentication::Digest::ControllerMethods, HttpAuthentication::Token::ControllerMethods, AbstractController::Callbacks, Rescue, Instrumentation, ParamsWrapper
  6. > AbstractController::Translation, > AbstractController::AssetPaths, > Helpers, < ApiRendering, > ActionView::Layouts,

    > Rendering, < BasicImplicitRender, > EtagWithTemplateDigest, > Caching, > MimeResponds, > ImplicitRender, > Cookies, > Flash, > FormBuilder, > RequestForgeryProtection, > Streaming, > HttpAuthentication::Basic::ControllerMethods, > HttpAuthentication::Digest::ControllerMethods, > HttpAuthentication::Token::ControllerMethods, diff
  7. BENCHMARK ▸ MacBookPro(Retina Mid 2012) ▸ Rails 5.0.0.beta3 ▸ Puma

    2.16.0 ▸ Scaffold+α ▸ return just 10 records ▸ no JSON Serializer ▸ production mode ▸ ab -n 1000 -c 10 http://127.0.0.1:3000/posts.json ▸ https://github.com/willnet/rails-api-benchmark
  8. curl http://localhost:3001/posts.json [{"id":1,"title":"λΠτϧ0","body":"ຊจ 0","created_at":"2016-02-27T08:51:00.583Z","updated_at":"2016-02-27T08:51:00.583Z"},{"id":2,"title":"λΠτϧ 1","body":"ຊจ1","created_at":"2016-02-27T08:51:00.587Z","updated_at":"2016-02-27T08:51:00.587Z"},{"id": 3,"title":"λΠτϧ2","body":"ຊจ 2","created_at":"2016-02-27T08:51:00.589Z","updated_at":"2016-02-27T08:51:00.589Z"},{"id":4,"title":"λΠτϧ 3","body":"ຊจ3","created_at":"2016-02-27T08:51:00.590Z","updated_at":"2016-02-27T08:51:00.590Z"},{"id": 5,"title":"λΠτϧ4","body":"ຊจ 4","created_at":"2016-02-27T08:51:00.592Z","updated_at":"2016-02-27T08:51:00.592Z"},{"id":6,"title":"λΠτϧ

    5","body":"ຊจ5","created_at":"2016-02-27T08:51:00.594Z","updated_at":"2016-02-27T08:51:00.594Z"},{"id": 7,"title":"λΠτϧ6","body":"ຊจ 6","created_at":"2016-02-27T08:51:00.596Z","updated_at":"2016-02-27T08:51:00.596Z"},{"id":8,"title":"λΠτϧ 7","body":"ຊจ7","created_at":"2016-02-27T08:51:00.598Z","updated_at":"2016-02-27T08:51:00.598Z"},{"id": 9,"title":"λΠτϧ8","body":"ຊจ 8","created_at":"2016-02-27T08:51:00.600Z","updated_at":"2016-02-27T08:51:00.600Z"},{"id":10,"title":"λΠτϧ 9","body":"ຊจ9","created_at":"2016-02-27T08:51:00.601Z","updated_at":"2016-02-27T08:51:00.601Z"}]