使用 curl、params 数组测试 Rails 葡萄 API [英] testing rails grape API with curl, params array
本文介绍了使用 curl、params 数组测试 Rails 葡萄 API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 curl 手动测试我的 rails 应用程序葡萄 API.我想发送一个 [1,2,3] 数组作为请求查询参数,以便可以访问:
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 .
如果您能提供如何使用 curl 发布数组的线索,我将不胜感激.
I will be grateful for a clue how to post an array using curl.
推荐答案
谢谢你的提示.答案是这样编码查询:
Thank you for the clue. The answer is to encode query like this:
?&tickets_ids[]=1&tickets_ids[]=2&tickets_ids[]=3
结果:
p params[:tickets_ids]
=> ["1", "2", "3"]
这篇关于使用 curl、params 数组测试 Rails 葡萄 API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文