Cover image for Match URI templates with Burrito

Match URI templates with Burrito

tfausak profile image Taylor Fausak ・1 min read

URI templates are a powerful way to succinctly describe URLs. For example the URI template https://hackage.haskell.org/package/{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: https://hackage.haskell.org/package/parsec.

>>> let Just template = parse "https://hackage.haskell.org/package/{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 "https://hackage.haskell.org/package/parsec" 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.

Posted on by:


markdown guide

I could never grasp well what Burrito was about by reading tweets. This post cleared it all up. Keep up the great work Taylor!


Thanks Riccardo! In case you missed it, I announced Burrito on my blog about a month ago: taylor.fausak.me/2020/04/05/burrito/. Hopefully the posts and documentation are a little more useful than my tweets 😆