servant-0.20.2: A family of combinators for defining webservices APIs

Safe Haskell | None
Language | Haskell2010

Servant.API.QueryString

Synopsis

- data QueryString
- data DeepQuery (sym :: Symbol) a
- class FromDeepQuery a where
  - fromDeepQuery :: [([Text], Maybe Text)] -> Either String a
- class ToDeepQuery a where
  - toDeepQuery :: a -> [([Text], Maybe Text)]
- generateDeepParam :: Text -> ([Text], Maybe Text) -> (Text, Maybe Text)

# Documentation

data QueryString #

Extract the whole query string from a request. This is useful for query strings containing dynamic parameter names. For query strings with static parameter names, `QueryParam` is more suited.

Example:

    >>> -- /books?author=<author name>&year=<book year>
    >>> type MyApi = "books" :> QueryString :> Get '[JSON] [Book]

data DeepQuery (sym :: Symbol) a #

Extract an deep object from a query string.

Example:

    >>> -- /books?filter[author][name]=<author name>&filter[year]=<book year>
    >>> type MyApi = "books" :> DeepQuery "filter" BookQuery :> Get '[JSON] [Book]

class FromDeepQuery a where #

Extract a deep object from (possibly nested) query parameters. a param like `filter[a][b][c]=d` will be represented as `'(["a", "b", "c"], Just "d")'`. Note that a parameter with no nested field is possible: `filter=a` will be represented as `'([], Just "a")'`

Methods

fromDeepQuery :: [([Text], Maybe Text)] -> Either String a #

#### Instances

Instances details

FromHttpApiData a => FromDeepQuery (Map Text a) # |
Instance details Defined in Servant.API.QueryString Methods fromDeepQuery :: [([Text], Maybe Text)] -> Either String (Map Text a) #

class ToDeepQuery a where #

Generate query parameters from an object, using the deep object syntax. A result of `'(["a", "b", "c"], Just "d")'` attributed to the `filter` parameter name will result in the following query parameter: `filter[a][b][c]=d`

Methods

toDeepQuery :: a -> [([Text], Maybe Text)] #

generateDeepParam :: Text -> ([Text], Maybe Text) -> (Text, Maybe Text) #

Turn a nested path into a deep object query param

    >>> generateDeepParam "filter" (["a", "b", "c"], Just "d")
    ("filter[a][b][c]",Just "d")