Interacting with APIs

APIs have a variety of structures to interact with their peers.

StackExchange API

require 'http'

json_res = JSON.parse(Net::HTTP.get(URI.parse "http://api.stackexchange.com/2.2/questions?site=stackoverflow"))

IPify API

require 'open-uri'
require 'json'
JSON.parse(URI.open('https://api.ipify.org?format=json').read)["ip"]

Last updated