如何使用grape在单个请求中传递查询参数和标头

时间:2014-07-14 07:53:10

标签: ruby-on-rails-3 ruby-on-rails-4 httparty grape grape-api

如何使用grape

在单个请求中传递查询参数和标题

如何使用post和query string params。它们之间有什么区别。我正在使用葡萄restful-api。葡萄

HTTP方法:POST

标题

秘密

查询字符串参数:

名称

年龄

例如

 post :student do
   name= params[:name]
   id = params[:id]
   query = {:name =>name, :id =>id}
   headers['key'] = "1988340998981183787898977"
   headers['sign'] = "1jkhhhajkaghvhgghgh9883dmkjkjkjkjk40998aaaadf1234981183787898977"

       HTTParty.post(url, :headers => headers, :query => query)
    end

1 个答案:

答案 0 :(得分:1)

标题的设置方式大致相同。您将headers选项传递给您选择的HTTP方法,并使用您要包含的标题的哈希值:

HTTParty.post("http://rubygems.org/api/v1/gems/httparty/owners",
:query => { :email => "alan+thinkvitamin@carsonified.com" },
:headers => { "Authorization" => "THISISMYAPIKEYNOREALLY"})

有关详细信息,请参阅Document