Home Blog Talks

Reasons for Choosing jsonapi-resources

2016-07-30

jsonapi-resources is a convenient gem for building APIs, including controller and resource.

In the official logs released with Rails 5, three gems for building APIs were recommended: Jbuilder, Active Model Serializers, and JSONAPI::Resources. The first two require use with rails-api, while only jsonapi-resources provides JSONAPI::ResourceController.

We ultimately chose jsonapi-resources mainly for the following reasons:

  1. Its resource syntax is similar to that of active_model_serializers, which we have used before.
  2. Active Model Serializers does not support the abstract feature and must be based on a model, whereas some of our resources are not based on models.
  3. jsonapi-resources has a built-in fields option, which allows for easy specification of the fields to be returned on the request side, rather than returning all fields.
  4. The returned data structure complies with the jsonapi specification.
  5. JSONAPI::ResourceController provides RESTful encapsulation, which can save a lot of code.

These reasons are just the most needed features for the current project, and there are more features that can be seen in the official documentation.

Reference links:

jsonapi-resources: https://github.com/cerebris/jsonapi-resources

jsonapi: http://jsonapi.org

Back to all posts