0

I am building a Rails API and am using Netflix's fast_jsonapi code to serialize my ActiveRecord objects:

class PerformancesController < ApplicationController

  def index
    render json: serialize(user.performances)
  end

  def serialize(data)
    PerformanceSerializer.new(data).serialized_json
  end

end

However, when the response returns, I have to access the data with response.data.data: enter image description here

This just seems awkward to me. Is there anyway to remove one of the data's?

Darkisa
  • 1,899
  • 3
  • 20
  • 40
  • Fast_jsonapi serializes payload according to OpenApi standard. So the payload is put under 'data' key. Seems you're using an HTTP library in your client that puts the response body under 'data' too (like Axios). Thus you have the duplication. You can change to a different lib, which maybe use a different key like 'body'. But I wouldn't bother if I were you. – EJAg Jun 15 '19 at 23:45
  • Ahhhh I am using axios. I never thought to look at the js library. Much appreciated! – Darkisa Jun 15 '19 at 23:47

0 Answers0