Skip to content

Instantly share code, notes, and snippets.

@rodneyrehm
Created August 11, 2012 14:58
Show Gist options
  • Select an option

  • Save rodneyrehm/3325071 to your computer and use it in GitHub Desktop.

Select an option

Save rodneyrehm/3325071 to your computer and use it in GitHub Desktop.
URI Template - extracting data

Extracting Data Through URI Templates

the following list is far from complete. It just lists what I could immediately think of…

Templates that cannot be used for extracting values:

  • http://example.com/{foo}{bar}
  • http://example.com/{foo,bar}
  • http://example.com/{?foo*}{&bar*}
  • ?one=alpha&two=bravo ~ ?two=bravo&one=alpha - while they are different URIs by way of RFC 3986, most web applications neither differentiate them, nor enforce one or the other. Since applications (usually) don't fail on "wrong parameter order", developers tend to handle this rather lax

Derived rules of non-extractability

  1. Multi-Variable-Expressions: {var1,var2}
  • OK: foo,bar -> {var1: "foo", var2: "bar"}
  • FAIL: foo,bar,baz -> {var1: ["foo", "bar"], var2: "baz"} or {var1: "foo", var2: ["bar", "baz"]} or {var1: ["foo", "bar", "baz"], var2: null} or {var1: null, var2: ["foo", "bar", "baz"]}
  1. Expression sequence: {var1}{var2}
  • no-matter the input, {var2} would always end up null or empty
  1. Exploded Query String expressions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment