Skip to content

Commit 05b78da

Browse files
authored
Exported Servant.Links.addQueryParam (#1785)
1 parent 3cb70ef commit 05b78da

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

changelog.d/issue-1232

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
synopsis: Exported addQueryParam
2+
packages: servant
3+
prs: #1785
4+
issues: #1232
5+
description: {
6+
`addQueryParams` is required to define custom `HasLink` instances which actually manipulate the
7+
generated query params. This function was not exported earlier and now it is.
8+
}

servant/src/Servant/Links.hs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ module Servant.Links (
115115
, linkSegments
116116
, linkQueryParams
117117
, linkFragment
118+
, addQueryParam
118119
) where
119120

120121
import Data.Kind
@@ -188,6 +189,10 @@ import Servant.API.MultiVerb
188189
-- | A safe link datatype.
189190
-- The only way of constructing a 'Link' is using 'safeLink', which means any
190191
-- 'Link' is guaranteed to be part of the mentioned API.
192+
--
193+
-- NOTE: If you are writing a custom 'HasLink' instance, and need to manipulate
194+
-- the 'Link' (adding query params or fragments, perhaps), please use the the
195+
-- 'addQueryParam' and 'addSegment' functions.
191196
data Link = Link
192197
{ _segments :: [Escaped]
193198
, _queryParams :: [Param]
@@ -233,10 +238,18 @@ data Param
233238
addSegment :: Escaped -> Link -> Link
234239
addSegment seg l = l { _segments = _segments l <> [seg] }
235240

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

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

0 commit comments

Comments
 (0)