Added accessor functions for link segments and query params

This commit is contained in:
Kirill Zaborsky 2017-03-22 17:22:32 +03:00
parent b0dbd79a06
commit e4a1292e98

View file

@ -88,6 +88,8 @@ module Servant.Utils.Links (
-- * Adding custom types
, HasLink(..)
, linkURI
, linkSegments
, linkQueryParams
, Link
) where
@ -121,6 +123,18 @@ data Link = Link
, _queryParams :: [Param Query]
} deriving Show
-- | Link path segments
linkSegments :: Link -> [String]
linkSegments = _segments
-- | Query params of a link, values are optional because of 'QueryFlag'
linkQueryParams :: Link -> [(String, Maybe String)]
linkQueryParams = map toKeyValue . _queryParams
where
toKeyValue (ArrayElemParam k v) = (k <> "[]", Just $ Text.unpack v)
toKeyValue (SingleParam k v) = (k, Just $ Text.unpack v)
toKeyValue (FlagParam k) = (k, Nothing)
instance ToHttpApiData Link where
toHeader = TE.encodeUtf8 . toUrlPiece
toUrlPiece l =