Text (printf) and JSON formatter for URLs.
Percent-encoded components are decoded by default. Use -e to keep them encoded.
Install with: cargo install furl
Can also be used as a library: cargo add furl
Examples:
}
}}
host='localhost' port='5432' db='db' user='usr' pwd='pwd'
scheme='https' query='q=rust+furl' path='/search' port=''
path='/wiki/Rust' fragment='Prevention'
path='/café' query='q=hello world'
JSON output
Use -j to output URL components as JSON. Only detected components are included.
Query parameters are expanded into a nested object.
|
{
}
Default ports (80 for http, 443 for https) are omitted unless -p is used:
}
}
Format string
The formatting string (-f) can contain any of the following substitutions:
%A - the path, without the starting '/'
%a - the path
%f - the fragment
%h - the hostname
%P - the password of the userinfo portion
%p - the port
%q - the query string
%s - the scheme
%U - the username of the userinfo portion
%n - newline (\n)
%t - tab (\t)
%% - a single %
Library usage
furl exposes a UrlParts struct for parsing URLs into typed components:
use UrlParts;
use Url;
let url = parse.unwrap;
let parts = from_url;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
// Display impl outputs JSON
println!;
// {"scheme":"https","user":"usr","password":"pwd","host":"example.com","path":"/path","query":{"a":"A","b":"B"},"fragment":"frag"}
format_url formats a URL using printf-style specifiers:
use format_url;
use Url;
let url = parse.unwrap;
let out = format_url;
assert_eq!;
Bash example
DPG="docker run -d --rm --name pg-%A -v vol-%A:/var/lib/postgresql \
-p %p:5432 \
-e POSTGRES_DB=%A -e POSTGRES_USER=%U -e POSTGRES_PASSWORD=%P \
postgres"