Parameters as Headers

Learn how to scrape websites using header-based parameters with ScraperAPI in Ruby. Pass api_key, render, and instruction_set via headers to simplify requests.

Along with the “traditional” means of passing parameters, we also support passing parameters as headers. Passing parameters such as api_key, render, ultra_premium and instruction_set is very straightforward.

  • API REQUEST

Instead of including the parameters in the URL

require 'net/http'
require 'uri'
require 'json'

# Define parameters including headers
params = {
  api_key: "<YOUR_API_KEY>",
  url: "http://httpbin.org/ip",
  render: true
}

# URI for the API endpoint (note: use HTTPS)
uri = URI('https://api.scraperapi.com/')
uri.query = URI.encode_www_form(params)

# Create a GET request
req = Net::HTTP::Get.new(uri)
req['Accept'] = 'application/json'
req['X-MyHeader'] = '123'

# Create an HTTPS connection
http = Net::HTTP.new(uri.hostname, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER

# Perform the HTTPS request
website_content = http.request(req)

# Output the response body
puts website_content.body

you can just pass them as headers

Please note that the 'x-sapi-' prefix is used on each header to avoid collisions with headers used by target sites. We support all standard parameters available with the API. The instruction_set parameter is specifically supported only through headers.

  • PROXY MODE

Note that credentials must still be passed to the proxy in the manner shown above, not as headers.

Last updated

Was this helpful?