I'm using ruby URI to build a basic uri and I'm confused about something.
Here is my code:
uri = URI("https://myhost.com")
uri.path << "/myapi/endpoint"
uri.query = "p1=value1&p2=value2"
uri.to_s
=> "https://myhost.com/myapi/endpoint?p1=value1&p2=value2"
This is all well and good but I don't understand why I can use <<
operator to set uri.path
but not uri.query
?
e.g., the follow code does not work for setting uri.query
uri = URI("https://myhost.com")
uri.path << "/myapi/endpoint"
uri.query << "p1=value1&p2=value2"