From e4a1292e98e49daf53b613beb17568e919b05821 Mon Sep 17 00:00:00 2001 From: Kirill Zaborsky Date: Wed, 22 Mar 2017 17:22:32 +0300 Subject: [PATCH] Added accessor functions for link segments and query params --- servant/src/Servant/Utils/Links.hs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/servant/src/Servant/Utils/Links.hs b/servant/src/Servant/Utils/Links.hs index ee7090e1..2ec5c00b 100644 --- a/servant/src/Servant/Utils/Links.hs +++ b/servant/src/Servant/Utils/Links.hs @@ -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 =