Sha256: 09cd3efe53710114b1eabe5c594975d0cbf538418cabb1b7c60a475d67cc503f

Contents?: true

Size: 1.91 KB

Versions: 6

Compression:

Stored size: 1.91 KB

Contents

# URI::Builder

URI builder makes working with URLs in Ruby a little less awkward by chaining methods calls that alter the URL. It looks like this:

```ruby
URI.build("https://www.example.com/api/v1").path("/api/v2").query(search: "great books").uri
```

Or if you prefer a block format that automatically converts back to an URI object after the transformation.

```ruby
URI.build("https://www.example.com/api/v1") { _1.path("/api/v2").query search: "great books" }
```

Compare that to:

```ruby
uri = URI("https://www.example.com/api/v1")
uri.path = "/api/v2"
uri.query = URI.encode_www_form(search: "great books")
uri
```

There's even a shortcut for working with URLs from ENV vars:

```ruby
URI.env("API_URL").path("/people/search").query(first_name: "Brad")
```

Compare that to:

```ruby
uri = URI ENV.fetch("API_URL")
uri.path = "/people/search"
uri.query = URI.encode_www_form(first_name: "Brad")
uri
```

Each chain creates a duplicate of the original URL, so you can transform away without worrying about thrashing the original URL object.

## Installation

Install the gem and add to the application's Gemfile by executing:

    $ bundle add uri-builder

If bundler is not being used to manage dependencies, install the gem by executing:

    $ gem install uri-builder

## Development

After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/rubymonolith/uri-builder.

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
uri-builder-0.1.12 README.md
uri-builder-0.1.11 README.md
uri-builder-0.1.10 README.md
uri-builder-0.1.9 README.md
uri-builder-0.1.7 README.md
uri-builder-0.1.6 README.md