-2

So I have this string URL for an HTTP request

http://locahost:3000/stuff?owner=foo bar+type=video game

I need to pass this as part of an HTTP get request to another ruby service. How do I encode this URL, i.e. take off the spaces and special characters and come up with the right request URL? Is there a gem to handle that. I know this could probably be done with some kind of regex, but I was hoping to find a standard gem that could do this.

absessive
  • 1,121
  • 5
  • 14
  • 36

1 Answers1

3
require 'uri'
uri_string = URI::encode("http://localhost:3000/stuff?owner=foo bar+type=video game")

Not sure how searching for "ruby url encode" or parsing etc. didn't find that for you.

Dave Newton
  • 158,873
  • 26
  • 254
  • 302