Skip to content

Commit

Permalink
Exported Servant.Links.addQueryParam
Browse files Browse the repository at this point in the history
  • Loading branch information
saurabhnanda committed Sep 23, 2024
1 parent 6014370 commit 32ad73d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion servant/servant.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 3.0
name: servant
version: 0.20.2
version: 0.20.3
synopsis: A family of combinators for defining webservices APIs
category: Servant, Web
description:
Expand Down
14 changes: 14 additions & 0 deletions servant/src/Servant/Links.hs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ module Servant.Links (
, linkSegments
, linkQueryParams
, linkFragment
, addQueryParam
, addSegment
) where

import Data.Kind
Expand Down Expand Up @@ -187,6 +189,10 @@ import Web.HttpApiData
-- | A safe link datatype.
-- The only way of constructing a 'Link' is using 'safeLink', which means any
-- 'Link' is guaranteed to be part of the mentioned API.
--
-- NOTE: If you are writing a custom 'HasLink' instance, and need to manipulate
-- the 'Link' (adding query params or fragments, perhaps), please use the the
-- 'addQueryParam' and 'addSegment' functions.
data Link = Link
{ _segments :: [Escaped]
, _queryParams :: [Param]
Expand Down Expand Up @@ -232,10 +238,18 @@ data Param
addSegment :: Escaped -> Link -> Link
addSegment seg l = l { _segments = _segments l <> [seg] }

-- | Add a 'Param' (query param) to a 'Link'
--
-- Please use this judiciously from within your custom 'HasLink' instances
-- to ensure that you don't end-up breaking the safe provided by "safe links"
addQueryParam :: Param -> Link -> Link
addQueryParam qp l =
l { _queryParams = _queryParams l <> [qp] }

-- | Add a 'Fragment' (query param) to a 'Link'
--
-- Please use this judiciously from within your custom 'HasLink' instances
-- to ensure that you don't end-up breaking the safe provided by "safe links"
addFragment :: Fragment' -> Link -> Link
addFragment fr l = l { _fragment = fr }

Expand Down

0 comments on commit 32ad73d

Please sign in to comment.