burrito-1.0.0.2: Parse and render URI templates.

Safe HaskellSafe
LanguageHaskell98

Burrito

Description

Burrito is a Haskell library for parsing and rendering URI templates.

According to RFC 6570: "A URI Template is a compact sequence of characters for describing a range of Uniform Resource Identifiers through variable expansion." Burrito implements URI templates according to the specification in that RFC.

The term "uniform resource identifiers" (URI) is often used interchangeably with other related terms like "internationalized resource identifier" (IRI), "uniform resource locator" (URL), and "uniform resource name" (URN). Burrito can be used for all of these. If you want to get technical, its input must be a valid IRI and its output will be a valid URI or URN.

Although Burrito is primarily intended to be used with HTTP and HTTPS URIs, it should work with other schemes as well.

If you're not already familiar with URI templates, I recommend reading the overview of the RFC. It's short, to the point, and easy to understand.

Assuming you're familiar with URI templates, here's a simple example to show you how Burrito works:

import Burrito
let Just template = parse "http://example.com/search{?query}"
expand [ ( "query", stringValue "bikes" ) ] template
"http://example.com/search?query=bikes"

In short, use parse to parse templates and expand to render them.

Synopsis

Documentation

parse :: String -> Maybe Template Source #

Attempts to parse a string as a URI template. If parsing fails, this will return Nothing. Otherwise it will return Just the parsed template.

Parsing will usually succeed, but it can fail if the input string contains characters that are not valid in IRIs (like ^) or if the input string contains an invalid template expression (like {!}). To include characters that aren't valid in IRIs, percent encode them (like %5E).

expand :: [(String, Value)] -> Template -> String Source #

Expands a template using the given values. Unlike parsing, expansion always succeeds. If no value is given for a variable, it will simply not appear in the output.

data Template Source #

Represents a URI template. Use parse to create a template and expand to render one.

Instances
Eq Template Source # 
Instance details

Defined in Burrito

Show Template Source # 
Instance details

Defined in Burrito

data Value Source #

Represents a value that can be substituted into a template. Can be a string, a list, or dictionary (which is called an associative array in the RFC). Use stringValue, listValue, and dictionaryValue to construct values.

Instances
Eq Value Source # 
Instance details

Defined in Burrito

Methods

(==) :: Value -> Value -> Bool #

(/=) :: Value -> Value -> Bool #

Show Value Source # 
Instance details

Defined in Burrito

Methods

showsPrec :: Int -> Value -> ShowS #

show :: Value -> String #

showList :: [Value] -> ShowS #

stringValue :: String -> Value Source #

Constructs a string Value.

listValue :: [String] -> Value Source #

Constructs a list Value.

dictionaryValue :: [(String, String)] -> Value Source #

Constructs a dictionary Value.