How can I customize jsonapi-rails response?

Viewed 23

Given a class User, I want to create a response with keys which value is a serialized User. For example:

{
  key1: user_list_1,
  key2: user_list_2,
  key3: user_list_3,
}

I already have a app/serializers/serializable_user.rb file. If I wanted only only list, would be like render jsonapi: user_list. How would this work with a custom response?

I could not find on documentation: http://jsonapi-rb.org/

1 Answers

Just found out after cloning the repo. You can create an instance of Renderer and call "render":

    renderer = JSONAPI::Serializable::Renderer.new
    {
       key1: renderer.render(user_list_1, class: SerializableUser),
       key2: renderer.render(user_list_2, class: SerializableUser),
       key3: renderer.render(user_list_3, class: SerializableUser)
    }

Related