Skip to content

Instantly share code, notes, and snippets.

Last active April 14, 2021 08:58
What would you like to do?
GraphQL with Ruby
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("")
header = {'Content-Type': 'application/json'; 'X-API-KEY': 'YOUR API KEY'}
query = "{ bitcoin { blocks { count } } }"
# Create the HTTP objects
http =, uri.port)
http.use_ssl = true
request =, header)
request.body = {query: query}.to_json
# Send the request
response = http.request(request)
puts "Body: #{response.body}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment