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
|
||||
, 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 =
|
||||
|
|
Loading…
Reference in a new issue