Skip to content

A simple command line utility that performs RFC 6570 URL Template expansion and does some other related things.

Notifications You must be signed in to change notification settings

MOZGIII/uritemplate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

urltemplate

A simple command line utility that performs RFC 6570 URL Template expansion and does some other related things.

Supports level 4 of RFC 6570.

Installation

$ go get github.com/MOZGIII/uritemplate

Usage

When run without arguments it displays detailed commands description.

$ uritemplate
usage: uritemplate [<flags>] <command> [<args> ...]

A command-line RFC6570 (URI Template) expander.

Flags:
  --help     Show context-sensitive help (also try --help-long and --help-man).
  --newline  Print newline at the end of output (use --no-newline to ommit
             newlines).

Commands:
  help [<command>...]
    Show help.

  expand [<flags>] <template>
    Print the expanded URI template.

  varnames [<flags>] <template>
    Print variable names found in the template.

  regexp <template>
    Print a regexp that matches the template.

URL Template expansion

For help check out uritemplate expand --help.

For more info on how exansion works, see section 3.2 of RFC 6570.

Simple variables

$ uritemplate expand "https://google.com/{?q}" --var q=test
https://google.com/?q=test

$ uritemplate expand "http://google.com/{?q}" --var "q=My Query"
http://google.com/?q=My%20Query

You can pass multiple --var options to expand more variables.

JSON variables

You can fully utilize level 4 expansion with JSON-encoded arguments.

$ uritemplate expand "http://google.com/{?q}" --json '{ "q": ["My Query", "My Other Query"] }'
http://google.com/?q=My%20Query,My%20Other%20Query

$ uritemplate expand "http://google.com/{?q*}" --json '{ "q": ["My Query", "My Other Query"] }'
http://google.com/?q=My%20Query&q=My%20Other%20Query

$ uritemplate expand "http://google.com/{?q*}" --json '{ "q": { "a": "My Query", "b": "My Other Query" } }'
http://google.com/?a=My%20Query&b=My%20Other%20Query

$ uritemplate expand "http://google.com/{?q}" --json '{ "q": { "a": "My Query", "b": "My Other Query" } }'
http://google.com/?q=a,My%20Query,b,My%20Other%20Query

Multiple --json options are allowed.

Regexp generation

$ uritemplate regexp "http://google.com/{?q}"
^(http://google\.com/)(?:\?((?:(?:[\x2c\x3d\x2d\x2e\x30-\x39\x41-\x5a\x5f\x61-\x7a\x7e]|%[[:xdigit:]][[:xdigit:]])*)))?$

Development

Feel free to send pull requests. Make sure code is formatted via go fmt and builds correctly.

About

A simple command line utility that performs RFC 6570 URL Template expansion and does some other related things.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages