Muhammad Faisal Iqbal
Muhammad Faisal Iqbal

Reputation: 1836

receive Array of hashes in API call rails

I 'm working on rails app in which I need to receive array of hashes in API call with Grape like.

{   
  tournament_id:1       
  match_id: 10
  [     
    {           
        team_id: 1                  
        score: 10   
     },     
     {          
        team_id: 2          
        score: 20   
      }
    ]
  }

so that I can receive score of each team in single call for a specific match and tournament instead of multiple calls for score of each team.

I have tried multiple things like

    group :teams_with_scores, type: Array, desc: "An array of Teams with scores" do
          requires :team_id, type: String,desc: "Team ID"
          requires :score, type: String,desc: "Score"
    end

But don't have a clue that how to do it.

Upvotes: 1

Views: 325

Answers (1)

gal
gal

Reputation: 779

You can send this data as a json string, and then parse this json when you get it:

params do
  scores_info, type: String, desc: 'the scores info'
end
get do
  scores_info = JSON.parse(params[:scores_info])
end

Upvotes: 2

Related Questions