Search code examples
ruby-on-railsapirablruby-grapejbuilder

Best Method to write an API application in Rails


I am planning to start a pure API only application using Rails4.2. As its a API application external clients makes requests to the app, no views are involved in the application. I would like to know what is the best method to build the application. Should I make use of gems like jbuilder/rabl or should I use gems like Grape? Which would be more efficient?


Solution

  • If you are going to use Rails, I recommend that you don't go with Grape. Here is the reason why I think so:

    1. You presumably already know some things about how to build Rails applications. All this knowledge can be applied to building an API. Grape, which was not built with Rails in mind, ends up duplicating a lot of the things Rails is doing, sometimes with some subtle differences, which only leads to confusion.
    2. Some things in Grape, like exception handling and logging are disparate from the Rails application. This can cause you some headaches down the road, if you wish to use something like New Relic.
    3. Versioning leads to a lot of duplication. You would be better off handling this with a non-intrusive gem like api-versions.

    There might be an option in rocket_pants, but from my experience, if you want to use Rails, and unless you have a strong rationale to do otherwise, I would recommend keeping it simple and just sticking with jbuilder or active_model_serializers.