ericgj/elm-uri-template/1.0.0

NOTE: the latest version is 1.0.1

Url.Interpolate

Url.Interpolate provides a single function, interpolate, which takes a [URI Template][rfc6570] string and a Dict of variables, and expands the input string according to the rules in [IETF RFC 6570][rfc6570], up to Level 3 (Level 4 compliance is not provided or planned).

interpolate : String -> Dict String String -> String

Example URI template interpolation:

interpolate "http://example.com/{path}{?x,y,empty}" <| Dict.fromList [("path", "hello"), ("x", "1024"), ("y", "768")]

"http://example.com/hello?x=1024&y=768&empty="

Internal note: I was surprised to find that the baseline %-encode rules for URI templates are slightly different than the built-in encodeURIComponent. For instance, '!' is escaped for the template operations that use the "unrestricted set" of unescaped characters, while the built-in does not escape it. Thus, we rely on the Hex library rather than Url.percentEncode.