Skip to content

Instantly share code, notes, and snippets.

@marinados
Last active February 24, 2016 13:38
Show Gist options
  • Save marinados/4d5cf0fd4c7efa6aedd1 to your computer and use it in GitHub Desktop.
Save marinados/4d5cf0fd4c7efa6aedd1 to your computer and use it in GitHub Desktop.

```rails new my_api --api````

*Configure your application to start with a more limited set of middleware than normal. Specifically, it will not include any middleware primarily useful for browser applications (like cookies support) by default. *Make ApplicationController inherit from ActionController::API instead of ActionController::Base. As with middleware, this will leave out any Action Controller modules that provide functionalities primarily used by browser applications. *Configure the generators to skip generating views, helpers and assets when you generate a new resource.

```config.api_only = true````

  • In config/application.rb for existing apps

```class ApplicationController < ActionController::API````

  • In application_controller.rb

ActionDispatch::Request#params

  • take parameters from the client in the JSON format and make them available in your controller inside params

Modules to add in ApplicationController or individual controllers AbstractController::Translation: Support for the l and t localization and translation methods. ActionController::HttpAuthentication::Basic (or Digest or Token): Support for basic, digest or token HTTP authentication. AbstractController::Layouts: Support for layouts when rendering. ActionController::MimeResponds: Support for respond_to. ActionController::Cookies: Support for cookies, which includes support for signed and encrypted cookies. This requires the cookies middleware.

More details here, including middleware and request headers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment