1

I have a route with /coordinates. I want to receive a JSON Array on this route, such as:

[
    {"latitude": 1, "longitude": 1},
    {"latitude": 1, "longitude": 2},
    {"latitude": 1, "longitude": 3}
]

How do I configure the params to parse this kind of data with grape? I don't want to give a name to the array such as { "blah": []}, I just want to read it from the request.

Here's what I'm trying to do

params do
  requires :latitude, type: Float
  requires :longitude, type: Float
end
post do
  route = Route.create(coordinates: params)
  { id: route.id }
end
Joe
  • 41,484
  • 20
  • 104
  • 125
  • You mean the entire request's body will be a JSON? – user3309314 Jan 17 '18 at 16:39
  • This is an area where grape I think has a shortcoming. I looked into it a while back and didn't come up with a satisfactory answer ("how do you declare a top-level nameless parameter") but am looking again. – Joe Jan 17 '18 at 23:10
  • So... this is not currently easy to do without rolling it yourself by parsing the overall payload. See: https://github.com/ruby-grape/grape/issues/1730 – Joe Jan 18 '18 at 02:21

0 Answers0