Skip to content

Instantly share code, notes, and snippets.

@ipetropolsky
Created April 23, 2014 16:26
Show Gist options
  • Save ipetropolsky/11222304 to your computer and use it in GitHub Desktop.
Save ipetropolsky/11222304 to your computer and use it in GitHub Desktop.
URI Template

URI Template — RFC6570

ImplementationsJS, Python.
Common test suite.

var template1 = UriTemplate("/date/{colour}/{shape}/");
var template2 = UriTemplate("/prefix/{?params*}");
var template3 = UriTemplate("{/id*}{?fields,token}");

template1.fillFromObject({colour: "green", shape: "round"});
// "/categories/green/round/"

template2.fillFromObject({
    params: {a: "A", b: "B", c: "C"}
});
// "/prefix/?a=A&b=B&c=C

template3.fromUri("/person/albums?fields=id,name,picture&token=12345");
/*
{
    id: ["person", "albums"],
    fields: ["id", "name", "picture"],
    token: "12345"
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment