Ruby on Rails Rails API Creating an API-only application

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

To build a Rails application that will be an API server, you can start with a more limited subset of Rails in Rails 5.

To generate a new Rails API app:

rails new my_api --api

What --api does is to remove functionality that is not needed when building an API. This includes sessions, cookies, assets, and anything that makes Rails work on a browser.

It will also configure the generators so that they don't generate views, helpers, and assets when generating a new resource.

When you compare the ApplicationController on a web app versus an API app, you will see that the web version extends from ActionController::Base, whereas the API version extends from ActionController::API, which includes a much smaller subset of functionality.



Got any Ruby on Rails Question?