How rails ActiveModel :: Serializers compare with grapes?

Can someone explain the difference between ActiveModel::Serializersand Grape. Should I use one or the other or use / should use them together. Can someone explain the benefits of using one (or both) of the above, but just using it railsyourself to build restful JSON API?

Thank you in advance

+4
source share
1 answer

Grape and ActiveModel serializers serve different purposes. Grape acts as a controller and router, and allows you to define the API for your application. In the Rails routes.rb file, you include a statement like this to pass routing to Grape:

mount API::Base, at: '/'

Then you create classes that inherit from Grape to define your API:

module API
  module V1
    class Companies < Grape::API

This is actually a gem that allows Grape to use Serializers ActiveModel: http://github.com/jrhe/grape-active_model_serializers

Grape, Rails. Grape , API. , Grape , , . , id , . . .

ActiveModel . . , , , (, ) . , , json. , . Serializer ActiveModel .

+12

All Articles