Command-line tool that helps with URI/URL handling and proper part extraction, escaping and parsing.
The following methods are available:
Directly download a version from the release page.
Install it on any system supporting snaps:
snap install uritool
Download the source code, review it and build it:
go test ./...
go build -mod=vendor .
This should build a local binary for your system with the name uritool
in your current working directory.
Encodes the given value to a valid query parameter value:
uritool query escape --no-newline "hello / world!%%"
# > hello+%2F+world%25%25
Decodes the given escaped query value:
uritool query unescape "hello+%2F+world%25%25"
# > hello / world!%%
Escape the given value to a valid escaped path value:
uritool path escape "hello world"
# > hello%20world
Unescape the given escaped path value:
uritool path unescape "hello%20world"
# > hello world
Parse a given URI and return all information as JSON:
uritool parse uri "https://my:[email protected]:8080/what/ ever?this=is&this=isnot#doing"
# > {
# > "Scheme": "https",
# > "Opaque": "",
# > "Username": "my",
# > "Password": "pass",
# > "PasswordIsGiven": true,
# > "Host": "the.example.com:8080",
# > "Hostname": "the.example.com",
# > "Port": 8080,
# > "Path": "/what/ ever",
# > "PathEscaped": "/what/%20ever",
# > "RawQuery": "this=is\u0026this=isnot",
# > "Fragment": "doing",
# > "Query": {
# > "this": [
# > "is",
# > "isnot"
# > ]
# > }
# > }
But sometimes you just want a specific part or combination of it, so use can use the go template language:
uritool parse uri --format="Welcome {{.Username}} from {{.Hostname}}" "https://adrian:[email protected]:8080/?uh=oh"
# > Welcome adrian from the.example.com
uritool parse uri --format="Second entry is {{index .Query.things 1}}" "https://adrian:[email protected]:8080/?things=one&things=two"
# > Second entry is two
You can also parse query strings (leading "?" will be removed):
uritool parse query "?this=is&this=isnot"
# > {
# > "this": [
# > "is",
# > "isnot"
# > ]
# > }
This is also workable with the go template language:
uritool parse query -n --format="{{index .search 0}}" "search=mister&filter=x"
# > mister