nyarly/elm-uri-template/1.0.0

Url.Interpolate

Url.Interpolate provides a primary entrypoint function, interpolate, which takes a URI Template string and a variable, and expands the input string according to the rules in IETF RFC 6570, up to Level 4.

interpolate : String -> Context -> String

Example URI template interpolation:

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


-- "<http://example.com/hello?x=1024&y=768&empty=">
type alias Context =
Dict String Value

the Context for a template interpolation

simpleContext : List ( String, String ) -> Context

Works like Dict.fromList to produce a context of names to Scalar string values; you could also use this to create an empty context like

simpleContext []
addScalar : Context -> String -> String -> Context

add a scalar (in other words a simple string) value to the context

addList : Context -> String -> List String -> Context

add a list of strings to the context

addAssoc : Context -> String -> Dict String String -> Context

add an associated list (in other words a map) to a context