Skip to content

Instantly share code, notes, and snippets.

@bclozel
Created December 23, 2013 12:30
Show Gist options
  • Save bclozel/8096305 to your computer and use it in GitHub Desktop.
Save bclozel/8096305 to your computer and use it in GitHub Desktop.
Comparing what RFC6570 based and "simple" URI template implementations can do.
/*
* RFC6570
*/
Map<String, Object> values = new HashMap<String, Object>();
values.put("count", Arrays.asList("one","two","three"));
UriComponentsBuilder.fromPath("{/count*}")
.buildAndExpand(values).encode().toUriString(); // "/one/two/three"
UriComponentsBuilder.fromPath("{?count*}")
.buildAndExpand(values).encode().toUriString(); // "?count=one&count=two&count=three"
UriComponentsBuilder.fromPath("{;count*}")
.buildAndExpand(values).encode().toUriString(); // ";count=one;count=two;count=three"
/*
* Current implementation
*/
/*
* RFC6570
*/
Map<String, Object> keys = new HashMap<String, Object>();
keys.put("foo","bar");
keys.put("uri","template");
keys.put("rfc","6570");
Map<String, Object> values = new HashMap<String, Object>();
values.put("keys", keys);
UriComponentsBuilder.fromPath("{?keys*}")
.buildAndExpand(values).encode().toUriString(); // "?foo=bar&uri=template&rfc=6570"
/*
* Current implementation
*/
/*
* RFC6570
*/
Map<String, Object> keys = new HashMap<String, Object>();
keys.put("foo","fooval");
keys.put("bar","barval");
keys.put("baz","bazval");
Map<String, Object> values = new HashMap<String, Object>();
values.put("keys", keys);
UriComponentsBuilder.fromPath("{/foo,/bar,/baz}") // same as "/{foo}/{bar}/{baz}"
.buildAndExpand(values).encode().toUriString(); // "/fooval/barval/bazval"
/*
* Current implementation
*/
UriComponentsBuilder.fromPath("{foo}").pathSegment("{bar}")
.pathSegment("baz").buildAndExpand(values).encode().toUriString(); // "/fooval/barval/bazval"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment