Added accessor functions for link segments and query params
This commit is contained in:
parent
b0dbd79a06
commit
e4a1292e98
1 changed files with 14 additions and 0 deletions
|
@ -88,6 +88,8 @@ module Servant.Utils.Links (
|
||||||
-- * Adding custom types
|
-- * Adding custom types
|
||||||
, HasLink(..)
|
, HasLink(..)
|
||||||
, linkURI
|
, linkURI
|
||||||
|
, linkSegments
|
||||||
|
, linkQueryParams
|
||||||
, Link
|
, Link
|
||||||
) where
|
) where
|
||||||
|
|
||||||
|
@ -121,6 +123,18 @@ data Link = Link
|
||||||
, _queryParams :: [Param Query]
|
, _queryParams :: [Param Query]
|
||||||
} deriving Show
|
} 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
|
instance ToHttpApiData Link where
|
||||||
toHeader = TE.encodeUtf8 . toUrlPiece
|
toHeader = TE.encodeUtf8 . toUrlPiece
|
||||||
toUrlPiece l =
|
toUrlPiece l =
|
||||||
|
|
Loading…
Reference in a new issue