@@ -84,6 +84,7 @@ module Servant.Utils.Links (
8484 --
8585 -- | Note that 'URI' is from the "Network.URI" module in the @network-uri@ package.
8686 safeLink
87+ , allLinks
8788 , URI(..)
8889 -- * Adding custom types
8990 , HasLink(..)
@@ -108,6 +109,7 @@ import Prelude ()
108109import Prelude.Compat
109110
110111import Web.HttpApiData
112+import Servant.API.Alternative ( (:<|>)((:<|>)) )
111113import Servant.API.BasicAuth ( BasicAuth )
112114import Servant.API.Capture ( Capture, CaptureAll )
113115import Servant.API.ReqBody ( ReqBody )
@@ -220,6 +222,16 @@ safeLink
220222 -> MkLink endpoint
221223safeLink _ endpoint = toLink endpoint (Link mempty mempty)
222224
225+-- | Create all links in an API.
226+--
227+-- Note that the @api@ type must be restricted to the endpoints that have
228+-- valid links to them.
229+allLinks
230+ :: forall api. HasLink api
231+ => Proxy api
232+ -> MkLink api
233+allLinks api = toLink api (Link mempty mempty)
234+
223235-- | Construct a toLink for an endpoint.
224236class HasLink endpoint where
225237 type MkLink endpoint
@@ -266,6 +278,11 @@ instance (KnownSymbol sym, HasLink sub)
266278 where
267279 k = symbolVal (Proxy :: Proxy sym)
268280
281+-- :<|> instance - Generate all links at once
282+instance (HasLink a, HasLink b) => HasLink (a :<|> b) where
283+ type MkLink (a :<|> b) = MkLink a :<|> MkLink b
284+ toLink _ l = toLink (Proxy :: Proxy a) l :<|> toLink (Proxy :: Proxy b) l
285+
269286-- Misc instances
270287instance HasLink sub => HasLink (ReqBody ct a :> sub) where
271288 type MkLink (ReqBody ct a :> sub) = MkLink sub