make a http get request in ruby

You can make an HTTP GET request in Ruby by utilizing the net/http library. Here's an example:

main.rb
require 'net/http'

uri = URI('https://jsonplaceholder.typicode.com/posts/1')
response = Net::HTTP.get(uri)

puts response
123 chars
7 lines

In this example, we're making a GET request to the JSONPlaceholder API to get the post with an ID of 1.

We first create a URI object with the URL that we want to request. Then, we use the Net::HTTP.get method to make the GET request and store the response in the response variable. Finally, we output the response to the console.

gistlibby LogSnag