git.iko.soy/typeable/servant
on master help sign in
Add doctests (and changelog)
commit2779f523caa1155429ab04f99630bfc385512022 authorOleg Grenrus <oleg.grenrus@iki.fi> dateTue 7 Nov 2017, 18:49 (9 years ago) parent7410b4f
2 files changed+17
servant/CHANGELOG.md+2 servant/src/Servant/Utils/Links.hs+15
servant/CHANGELOG.md+2
@@ -30,6 +30,8 @@
3030 [#767](https://github.com/haskell-servant/servant/pull/767)
3131 [#790](https://github.com/haskell-servant/servant/pull/790)
3232 [#788](https://github.com/haskell-servant/servant/pull/788))
33+- Add `addLinks` to generate all links for unnested APIs.
34+ ([#851](https://github.com/haskell-servant/servant/pull/851))
3335- Allow newest dependencies
3436 ([#772](https://github.com/haskell-servant/servant/pull/772)
3537 [#842](https://github.com/haskell-servant/servant/pull/842))
servant/src/Servant/Utils/Links.hs+15
@@ -226,6 +226,20 @@ safeLink _ endpoint = toLink endpoint (Link mempty mempty)
226226--
227227-- Note that the @api@ type must be restricted to the endpoints that have
228228-- valid links to them.
229+--
230+-- >>> type API = "foo" :> Capture "name" Text :> Get '[JSON] Text :<|> "bar" :> Capture "name" Int :> Get '[JSON] Double
231+-- >>> let fooLink :<|> barLink = allLinks (Proxy :: Proxy API)
232+-- >>> :t fooLink
233+-- fooLink :: Text -> Link
234+-- >>> :t barLink
235+-- barLink :: Int -> Link
236+--
237+-- Note: nested APIs don't work well with this approach
238+--
239+-- >>> :kind! MkLink (Capture "nest" Char :> (Capture "x" Int :> Get '[JSON] Int :<|> Capture "y" Double :> Get '[JSON] Double))
240+-- MkLink (Capture "nest" Char :> (Capture "x" Int :> Get '[JSON] Int :<|> Capture "y" Double :> Get '[JSON] Double)) :: *
241+-- = Char -> (Int -> Link) :<|> (Double -> Link)
242+--
229243allLinks
230244 :: forall api. HasLink api
231245 => Proxy api
@@ -330,3 +344,4 @@ instance HasLink sub => HasLink (AuthProtect tag :> sub) where
330344
331345-- $setup
332346-- >>> import Servant.API
347+-- >>> import Data.Text (Text)