testing rails grape API with curl, params array

折月煮酒 提交于 2019-12-07 14:31:30

问题


I am manually testing my rails application grape API using curl. I would like to send a [1,2,3] array as a request query parameter for to to be accesible like:

p params[:tickets_ids]
=> [1,2,3]

I only found clues how to send something what is interpreted as hash .

I will be grateful for a clue how to post an array using curl.


回答1:


Thank you for the clue. The answer is to encode query like this:

?&tickets_ids[]=1&tickets_ids[]=2&tickets_ids[]=3

Results in:

p params[:tickets_ids]
=> ["1", "2", "3"]


来源:https://stackoverflow.com/questions/18314017/testing-rails-grape-api-with-curl-params-array

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!