0

managed to submit a simple array to my grape api following this tip

testing rails grape API with curl, params array

Building a simple workout tracker that generates a graph at the end, through this array of workouts, which should be passed with their keys I guess.

But since what i'm trying to do is a 2D array, i have this output, the type is set to Array[Array], this is the call that i'm currently using

 curl --data 'workouts_array[]=1&workouts_array[]=2&workouts_array[]=3' http://localhost:3000/api/v1/workouts/workout.json

And it returns

{
"workouts_array": [
    [
      "1"
    ],
    [
      "2"
    ],
    [
      "3"
    ]
  ]
}

But i wish to pass something like workouts_array[]=[1][2][3]&workouts_array[]=[4][5][6]

so it returns

{
"workouts_array": [
    [
      "time": "1", "distance": "2",  "calories": "3",
    ],
    [
      "time": "4", "distance": "5",  "calories": "6",
    ]
  ]
}

Thank you for any help, I guess it's just my poor way of using curl

Community
  • 1
  • 1
alexanderkustov
  • 496
  • 1
  • 5
  • 16

1 Answers1

2

I'm not sure that I correctly understood you but for your case you can use this query workouts_array[0]=1&workouts_array[0]=2&workouts_array[0]=3 &workouts_array[1]=4&workouts_array[1]=5&workouts_array[1]=6

it should return smth similar to:

[
  [
   "1",
   "2",
   "3"
  ],
  [
   "1",
   "2",
   "3"
  ]
]

this is array of arrays.

you says you set the type Array[Array] but wanna see the array of hashes. it's kinda different.

BTW, I prefer use JSON payload for those things.

macabeus
  • 4,156
  • 5
  • 37
  • 66
Dmitry Dedov
  • 1,106
  • 7
  • 15