Skip to content
/ uri Public

A commandline tool to resolve URI Templates expressions as specified in RFC 6570.

License

Notifications You must be signed in to change notification settings

lucasepe/uri

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

URI

Are you tired to build, concat, replace URL(s) (via shell scripts sed/awk/tr) from your awesome commandline pipeline?

Well! here is the missing piece: uri!

         _            _  
o  / / _|     URI      |_ 
o / /   |_ Templates  _|

A commandline tool to resolve URI Templates expressions as specified in RFC 6570.

For a complete syntax reference check the RFC6570 specs here: https://tools.ietf.org/html/rfc6570#section-2.

Expressions are placeholders which are to be substituted by the values their variables reference.

http://example.org/~{username}/
http://example.org/dictionary/{term:1}/{term}
http://example.org/search{?q*,lang}

How to use uri

This tool takes a JSON as input data model containing the values ​​of the variables. Example:

{
    "username": "scarlett",
    "term": "black widow",
    "q": {
        "a": "mars",
        "b": "jupiter"
    },
    "lang": "en"
}

You can pass this JSON as file using the -i flag:

$ uri -i data.json http://example.org/~{username}/{term:1}/{term}{?q*,lang}
http://example.org/~scarlett/b/black%20widow?q*

Or you can pipe it directly to the tool (and this the most interesting use case):

$ cat data.json | uri http://example.org/~{username}/{term:1}/{term}{?q*,lang}
http://example.org/~scarlett/b/black%20widow?q*

Using commandline pipes you can achieve tasks like this:

$ cat testdata/pets.json \
  | jq --raw-output '.pets[1] | {category: .species, year: .birthYear}' \
  | uri https://pets.api.com/{category}{?year} \
  | xargs curl

Installation Steps

In order to use the crumbs command, compile it using the following command:

go get -u github.com/lucasepe/uri

This will create the executable under your $GOPATH/bin directory.

Ready-To-Use Releases

If you don't want to compile the source code yourself, here you can find the executables for:

  • MacOS
  • Linux (amd64, arm7, arm64)
  • Windows

Credits

uri was possible thanks to the Joshua Tacoma URI Template library.