2015-04-20 19:52:29 +02:00
|
|
|
{-# LANGUAGE CPP #-}
|
2015-02-24 10:28:23 +01:00
|
|
|
{-# LANGUAGE DeriveDataTypeable #-}
|
2015-09-28 18:17:22 +02:00
|
|
|
{-# LANGUAGE DeriveFoldable #-}
|
2018-03-11 16:58:31 +01:00
|
|
|
{-# LANGUAGE DeriveFunctor #-}
|
2015-09-28 18:06:49 +02:00
|
|
|
{-# LANGUAGE DeriveTraversable #-}
|
2015-02-24 10:28:23 +01:00
|
|
|
{-# LANGUAGE TypeOperators #-}
|
2015-05-02 03:21:03 +02:00
|
|
|
{-# OPTIONS_HADDOCK not-home #-}
|
2015-02-24 10:28:23 +01:00
|
|
|
module Servant.API.Alternative ((:<|>)(..)) where
|
2014-10-25 01:27:39 +02:00
|
|
|
|
2018-03-11 16:58:31 +01:00
|
|
|
import Data.Semigroup
|
|
|
|
(Semigroup (..))
|
|
|
|
import Data.Typeable
|
|
|
|
(Typeable)
|
2016-03-01 19:25:04 +01:00
|
|
|
import Prelude ()
|
|
|
|
import Prelude.Compat
|
2016-03-01 12:21:21 +01:00
|
|
|
|
2014-10-25 01:27:39 +02:00
|
|
|
-- | Union of two APIs, first takes precedence in case of overlap.
|
2014-11-22 15:08:25 +01:00
|
|
|
--
|
|
|
|
-- Example:
|
|
|
|
--
|
2015-02-24 10:28:23 +01:00
|
|
|
-- >>> :{
|
|
|
|
--type MyApi = "books" :> Get '[JSON] [Book] -- GET /books
|
|
|
|
-- :<|> "books" :> ReqBody '[JSON] Book :> Post '[JSON] () -- POST /books
|
|
|
|
-- :}
|
2014-10-25 01:27:39 +02:00
|
|
|
data a :<|> b = a :<|> b
|
2015-09-28 18:06:49 +02:00
|
|
|
deriving (Typeable, Eq, Show, Functor, Traversable, Foldable, Bounded)
|
2017-06-02 17:11:05 +02:00
|
|
|
infixr 3 :<|>
|
2015-02-24 10:28:23 +01:00
|
|
|
|
2017-01-19 18:04:36 +01:00
|
|
|
instance (Semigroup a, Semigroup b) => Semigroup (a :<|> b) where
|
|
|
|
(a :<|> b) <> (a' :<|> b') = (a <> a') :<|> (b <> b')
|
|
|
|
|
2015-02-24 10:28:23 +01:00
|
|
|
instance (Monoid a, Monoid b) => Monoid (a :<|> b) where
|
|
|
|
mempty = mempty :<|> mempty
|
|
|
|
(a :<|> b) `mappend` (a' :<|> b') = (a `mappend` a') :<|> (b `mappend` b')
|
|
|
|
|
|
|
|
-- $setup
|
|
|
|
-- >>> import Servant.API
|
|
|
|
-- >>> import Data.Aeson
|
|
|
|
-- >>> import Data.Text
|
|
|
|
-- >>> data Book
|
|
|
|
-- >>> instance ToJSON Book where { toJSON = undefined }
|