on 207f398 help sign in
26 lines 847 B history raw
1{-# LANGUAGE TypeFamilies #-}
2{-# LANGUAGE TypeOperators #-}
3{-# LANGUAGE ScopedTypeVariables #-}
4module Servant.API.Union where
6import Data.Proxy
7import Servant.Client
8import Servant.Server
10-- | Union of two APIs, first takes precedence in case of overlap.
11data a :<|> b = a :<|> b
12infixr 8 :<|>
14instance (HasServer a, HasServer b) => HasServer (a :<|> b) where
15 type Server (a :<|> b) = Server a :<|> Server b
16 route Proxy (a :<|> b) request = do
17 m <- route (Proxy :: Proxy a) a request
18 case m of
19 Nothing -> route (Proxy :: Proxy b) b request
20 Just response -> return $ Just response
22instance (HasClient a, HasClient b) => HasClient (a :<|> b) where
23 type Client (a :<|> b) = Client a :<|> Client b
24 clientWithRoute Proxy req =
25 clientWithRoute (Proxy :: Proxy a) req :<|>
26 clientWithRoute (Proxy :: Proxy b) req