on e255b1f help sign in
26 lines 936 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) globalPathInfo request respond = do
17 route (Proxy :: Proxy a) a globalPathInfo request $ \ mResponse ->
18 case mResponse of
19 Nothing -> route (Proxy :: Proxy b) b globalPathInfo request respond
20 Just response -> respond $ 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