Before you get too excited and run rails new thecoolest --api on your terminal, you need to take some time to consider what your needs are.

How to choose which Rails alternative to implement your API?

To help you decide which Rails alternative you should use, here is a comparison of the most common API scenarios:

RequirementsRails API-onlyFull Rails stack
Login/logout (sessions)NY
Social logins (FB, Google)NY
Render HTML (web interfaces)NY
HTTP Header AuthenticationYY

If your client will be a SPA (single-page application) or a native mobile app, and that’s where all the user interaction is going to live, then Rails API-only is a good choice.

In general, if you need to render HTML pages or files, you’ll be better off building an API on top of a Rails app.

Sidenote: if you’re building an API, please consider following the OpenAPI specification. You can use Swagger for implementing it. rwsagger is the most popular option.

Keep in mind that you can still turn your Rails API-only into a full stack Rails app. But if you could skip all that work, why not? It’s like Einstein said:

If I had an hour to solve a problem and my life depended on it, I would spend the first 55 minutes determining the problem and five minutes thinking about the solution.

If you found this post helpful, sign up to get more content like this in your inbox! :)