Match URI templates with Burrito

by Taylor Fausak on

URI templates are a powerful way to succinctly describe URLs. For example the URI template{name} shows you how to find a Haskell package on Hackage. By expanding that template with name := "parsec" you can get the full URL of a package:

>>> let Just template = parse "{name}"
>>> expand [("name", stringValue "parsec")] template

RFC 6570 specifies how URI templates work. Unfortunately it doesn’t describe how to go in the other direction. That is, how to take a full URL and parse it according to a template. For example you may want to take a package URL and match it against the template to get the package name. This is kind of like doing template expansion in reverse.

>>> match "" template
[[("name", String "parsec")]]

I’m happy to announce that version of Burrito, my URI template library for Haskell, can now perform this matching operation! So if you find yourself needing to expand or match URI templates, please check it out.