Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- expandTH :: [(String, Value)] -> Template -> Q Exp
- uriTemplate :: QuasiQuoter
Documentation
expandTH :: [(String, Value)] -> Template -> Q Exp Source #
This can be used together with the TemplateHaskell
language extension to
expand a URI template at compile time. This is slightly different from
expand
in that missing variables will throw an exception. This is
convenient because it allows you to verify that all of the variables have
been supplied at compile time.
>>>
:set -XQuasiQuotes -XTemplateHaskell
>>>
import Burrito
>>>
$( expandTH [("foo", stringValue "bar")] [uriTemplate|l-{foo}-r|] )
"l-bar-r"
uriTemplate :: QuasiQuoter Source #
This can be used together with the QuasiQuotes
language extension to
parse a URI template at compile time. This is convenient because it allows
you to verify the validity of the template when you compile your file as
opposed to when you run it.
>>>
:set -XQuasiQuotes
>>>
import Burrito
>>>
let template = [uriTemplate|http://example/search{?query}|]
>>>
let values = [("query", stringValue "chorizo")]
>>>
expand values template
"http://example/search?query=chorizo"
Note that you cannot use escape sequences in this quasi-quoter. For example,
this is invalid: [uriTemplate|\xa0|]
. You can however use percent encoded
triples as normal. So this is valid: [uriTemplate|%c2%a0|]
.