ruby-on-railsrubyruby-on-rails-7rails-apiactioncontroller

ActionController::API vs ActionController::Base


I want to know what all functionalities are restricted in API and will there be any difference in speed if we use Base in place of API.

I searched many places to find the difference between those two modules, all I was able to know it API is light weight version of Base.


Solution

  • The best source to understand the differences between both is certainly the list of modules they include in the source code.

    Which ActionController::Base includes these modules (comments removed and sorted alphabetically):

    MODULES = [
      AbstractController::AssetPaths,
      AbstractController::Callbacks,
      AbstractController::Rendering,
      AbstractController::Translation,
      ActionView::Layouts,
      Caching,
      ConditionalGet,
      ContentSecurityPolicy,
      Cookies,
      DataStreaming,
      DefaultHeaders,
      EtagWithFlash,
      EtagWithTemplateDigest,
      Flash,
      FormBuilder,
      Helpers,
      HttpAuthentication::Basic::ControllerMethods,
      HttpAuthentication::Digest::ControllerMethods,
      HttpAuthentication::Token::ControllerMethods,
      ImplicitRender,
      Instrumentation,
      Logging,
      MimeResponds,
      ParameterEncoding,
      ParamsWrapper,
      PermissionsPolicy,
      Redirecting,
      Renderers::All,
      Rendering,
      RequestForgeryProtection,
      Rescue,
      Streaming,
      StrongParameters,
      UrlFor,
    ]
    

    While ActionController::API only includes these (again, comments removed and sorted alphabetically):

    MODULES = [
      AbstractController::Callbacks,
      AbstractController::Rendering,
      ApiRendering,
      BasicImplicitRender,
      ConditionalGet,
      DataStreaming,
      DefaultHeaders,
      Instrumentation,
      Logging,
      ParamsWrapper,
      Redirecting,
      Renderers::All,
      Rescue,
      StrongParameters,
      UrlFor,
    ]