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:
- Its resource syntax is similar to that of active_model_serializers, which we have used before.
- 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.
- 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.
- The returned data structure complies with the jsonapi specification.
- 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