Networking Basics
URI Parts
The URI library splits a web address into scheme, host, path, and query parts.
URI Parts
uri_parts.rb
require "uri"
raw_url =
uri = URI.parse(raw_url)
scheme = uri.scheme
host = uri.host
path = uri.path
query = uri.query || "none"
puts "scheme=#{scheme}"
puts "host=#{host}"
puts "path=#{path}"
puts "query=#{query}"
require "uri"
raw_url =
uri = URI.parse(raw_url)
scheme = uri.scheme
host = uri.host
path = uri.path
query = uri.query || "none"
puts "scheme=#{scheme}"
puts "host=#{host}"
puts "path=#{path}"
puts "query=#{query}"
require "uri"
raw_url =
uri = URI.parse(raw_url)
scheme = uri.scheme
host = uri.host
path = uri.path
query = uri.query || "none"
puts "scheme=#{scheme}"
puts "host=#{host}"
puts "path=#{path}"
puts "query=#{query}"
uri parse
`URI.parse` turns an address string into a structured object without opening a network connection.