@@ -115,6 +115,7 @@ module Servant.Links (
115
115
, linkSegments
116
116
, linkQueryParams
117
117
, linkFragment
118
+ , addQueryParam
118
119
) where
119
120
120
121
import Data.Kind
@@ -188,6 +189,10 @@ import Servant.API.MultiVerb
188
189
-- | A safe link datatype.
189
190
-- The only way of constructing a 'Link' is using 'safeLink', which means any
190
191
-- '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.
191
196
data Link = Link
192
197
{ _segments :: [Escaped ]
193
198
, _queryParams :: [Param ]
@@ -233,10 +238,18 @@ data Param
233
238
addSegment :: Escaped -> Link -> Link
234
239
addSegment seg l = l { _segments = _segments l <> [seg] }
235
240
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"
236
245
addQueryParam :: Param -> Link -> Link
237
246
addQueryParam qp l =
238
247
l { _queryParams = _queryParams l <> [qp] }
239
248
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"
240
253
addFragment :: Fragment' -> Link -> Link
241
254
addFragment fr l = l { _fragment = fr }
242
255
0 commit comments