Disclaimer: Rails 5 is currently under heavy and active development, and everything written in this blog post is subject to change(changing is the only constant). And this post mainly serves as my self help study notes.
I decided to find out the difference between an API only Rails 5 project and a normal Rails 4.2.4 project.
So I generated two new Rails projects and looked into Gemfile first.
Firstly, in the 4.2.4 version Gemfile, we have
web-console installed by default; and in the Rails 5 API version Gemfile, these gems are removed as they are no longer needed.
jbuilder is removed and currently replaced by
active_model_serializers. There is a debate regarding which gem is a better default choice in Rails 5, and you could read more in this pull request. I have never seriously worked with these two gems, but I am more into the
active_model_serializers approach by using serializers and adapters, instead of defining a “static” JSON template file in the jbuilder way, but that is only my personal preference for now.
sdoc is removed in Rails 5 API version Gemfile and currently there is no replacement, but we do have a few gem choices regarding API document generation on Github. And README.rdoc is also replaced by README.md in the root directory accordingly.
sprockets has been added into the Gemfile in Rails 5 Gemfile, so it is officially not a core feature of Rails anymore.
rack-cors is added into the Gemfile in Rails 5 API version to handle cross-origin AJAX stuff, but it’s by default commented out.
tzinfo-data are added in the Rails 5 API only version Gemfile as well.
Secondly I took a look into the app directory.
In the Rails 5 API only project, directory
views are removed and a new directory
jobs is added.
ApplicationController is now inherited from
ActionController::API instead of
Thirdly I took at
These lines are added into the file.
Ok! Great to know!
That’s all for part 1.