如何使用grape-api解码GET请求中的编码查询参数

问题描述 投票:0回答:1

我正在使用grape-api,并且在使用编码查询参数的前端服务中发出GET请求时遇到问题。这是我的端点设置为接收参数的方式:

params do
  requires :event_id, type: String, desc: 'Event id'
  requires :tickets, type: Array, desc: 'Array of each ticket data ex:  [ {id: "", count: 1 , coupon_code: ""} ]', allow_blank: false do
    requires :id, type: String, desc: 'Ticket id'
    requires :count, type: Integer, desc: 'Number of tickets to get'
    optional :coupon_code, type: String, desc: 'Promocode to apply if any'
  end
end

您可以看到,我期望有一个[[event_id参数和另一个对象数组<< tickets>,这是请求URL的样子:http://localhost:3000/api/service_fees/calculate?eventId=2xy6rft69azlu2mtppnzb1xe6olzd3f0&tickets[]=%7B%22id%22:%22vohd3y3n25cdgbvi3uzmqhcyie3zi53a%22,%22count%22:2%7D

但是,grape似乎不了解这些编码的查询参数,但出现此异常:

[Exception: event_id is missing, tickets[0][id] is missing, tickets[0][id] is invalid, tickets[0][count] is missing, tickets[0][count] is invalid]

我的问题是:有没有办法告诉葡萄正确解码和解析查询参数?我在这里想念什么吗?

我正在使用grape-api,并且在使用编码查询参数从前端服务发出GET请求时遇到问题。这是设置端点以接收参数的方式:参数确实需要:...
ruby-on-rails ruby rack grape grape-api
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.