DEV Community

Cover image for Match URI templates with Burrito
Taylor Fausak
Taylor Fausak

Posted on

Match URI templates with Burrito

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.

Top comments (2)

riccardoodone profile image
Riccardo Odone

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

tfausak profile image
Taylor Fausak

Thanks Riccardo! In case you missed it, I announced Burrito on my blog about a month ago: Hopefully the posts and documentation are a little more useful than my tweets 😆