1

I have successfully built an api as you can see here and the code is below. I need to list the objects as a nested array and not an array of objects, but I cannot figure it out.

api/v1/plaques.rb

module API  
    module V1
      class Plaques < Grape::API
        include API::V1::Defaults

        resource :plaques do
          desc 'Return all Plaques'
          get '', root: :plaques do
            Plaque.all
          end

          desc 'Return a Plaque'
          params do
            requires :id, type: String, desc: 'ID of Plaque'
          end
          get ':id', root: 'plaque' do
            Plaque.where(id: permitted_params[:id]).first!
          end
        end
      end
    end
  end 

What I'm getting:

[
    {
    "veteran_first": "Alexis",
     ...
    }
]

What I need:

 "items" =  [
        {
        "veteran_first": "Alexis",
         ...
        }
    ]
sfjac
  • 7,119
  • 5
  • 45
  • 69
Charles Smith
  • 3,201
  • 4
  • 36
  • 80

1 Answers1

1

This code returns JSON you want:

get '', root: :plaques do
  { items: Plaque.all }
end
user3309314
  • 2,453
  • 2
  • 17
  • 30