Last active
April 14, 2021 08:58
-
-
Save buddies2705/758ec13469e44e944e787b94fde41869 to your computer and use it in GitHub Desktop.
GraphQL with Ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/http' | |
require 'uri' | |
require 'json' | |
uri = URI.parse("https://graphql.bitquery.io/") | |
header = {'Content-Type': 'application/json'; 'X-API-KEY': 'YOUR API KEY'} | |
query = "{ bitcoin { blocks { count } } }" | |
# Create the HTTP objects | |
http = Net::HTTP.new(uri.host, uri.port) | |
http.use_ssl = true | |
request = Net::HTTP::Post.new(uri.request_uri, 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