Sam
Sam

Reputation: 5250

How to pass query params and headers in a single request using grape

How to pass query params and headers in a single request using grape

How to use post and query string params. What is the difference between them. I am using grape restful-api. Grape

HTTP method: POST

headers:

key

secret

Query string parameters:

name

age

For example

 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

Upvotes: 0

Views: 1248

Answers (1)

Abdul Baig
Abdul Baig

Reputation: 3721

Headers are set in about the same way. You pass the headers option to your chosen HTTP method with a hash of the headers you would like to include:

HTTParty.post("http://rubygems.org/api/v1/gems/httparty/owners",
:query => { :email => "[email protected]" },
:headers => { "Authorization" => "THISISMYAPIKEYNOREALLY"})

for more details see Document

Upvotes: 1

Related Questions