urlmatic

Crates.iourlmatic
lib.rsurlmatic
version0.5.0
sourcesrc
created_at2022-05-19 01:08:42.791462
updated_at2022-06-10 20:31:42.386834
descriptionSlice and dice URLs on the command line
homepage
repositoryhttps://github.com/bww/urlmatic
max_upload_size
id589436
size21,336
Brian W. Wolter (bww)

documentation

README

URL-matic

Perform some useful manipulation of URLs. This thing doesn't do much yet.

Resolve a URL Against a Base

Resolves a relative URL against the provided base URL and prints the result.

$ urlmatic resolve --base 'https://www.example.com/documents/letter.html?length=100' '../index.html?length=200'
> https://www.example.com/index.html?length=200

Trim Path Components from a URL

Removes the specified number of components from the end of a URL's path and prints the result.

$ urlmatic trim --count 2 'https://www.example.com/documents/letter.html?length=100'
> https://www.example.com/?length=100

Rewrite a URL by Replacing Components

Replace specific components in a URL and print the result.

$ urlmatic rewrite \
    --username admin \
    --host another.com \
    --path /cgi-bin/q \
    --query 'offset=0&length=100' \
    --fragment 'anchor-name' \
    https://example.com/query
> https://admin@another.com/cgi-bin/q?offset=0&length=100#anchor-name

Encode a Query String as application/x-www-form-urlencoded data

URL-encode form data form/query data.

$ urlmatic encode -k yep -v 👍 -k nope -v 👎
> yep=%F0%9F%91%8D&nope=%F0%9F%91%8E
$ urlmatic encode yep=👍 nope=👎
> nope=%F0%9F%91%8E&yep=%F0%9F%91%8D

Decode a Query String as application/x-www-form-urlencoded data

URL-decode form data and extract values.

$ urlmatic decode 'yep=%F0%9F%91%8D&nope=%F0%9F%91%8E'
>  yep: 👍
> nope: 👎
$ urlmatic decode --select yep 'yep=%F0%9F%91%8D&nope=%F0%9F%91%8E'
> 👍
$ urlmatic decode --select nope,yep 'yep=%F0%9F%91%8D&nope=%F0%9F%91%8E'
> 👍
> 👎

Put it All Together

Compose and modify a URL using a few commands.

$ echo 'https://example.com/path/to/query' |
    urlmatic rewrite --host another.com --query $(urlmatic encode -k yep -v 👍) |
    urlmatic trim --count 2
> https://another.com/path?yep=%F0%9F%91%8D
Commit count: 38

cargo fmt