on 13664a2 help sign in
39 lines 1.2 kB history raw
1{-# LANGUAGE PolyKinds #-}
2{-# LANGUAGE TypeFamilies #-}
3{-# LANGUAGE TypeOperators #-}
4{-# LANGUAGE ScopedTypeVariables #-}
5module Servant.API.Sub where
7import Data.Proxy
8import Data.String.Conversions
9import GHC.TypeLits
10import Network.Wai
11import Servant.Client
12import Servant.Server
14-- | The contained API (second argument) can be found under @("/" ++ path)@
15-- (path being the first argument).
16data (path :: k) :> a = Proxy path :> a
17infixr 9 :>
19instance (KnownSymbol path, HasServer sublayout) => HasServer (path :> sublayout) where
20 type Server (path :> sublayout) = Server sublayout
21 route Proxy subserver request = case pathInfo request of
22 (first : rest)
23 | first == cs (symbolVal proxyPath)
24 -> route (Proxy :: Proxy sublayout) subserver request{
25 pathInfo = rest
26 }
27 _ -> return Nothing
29 where proxyPath = Proxy :: Proxy path
31instance (KnownSymbol path, HasClient sublayout) => HasClient (path :> sublayout) where
32 type Client (path :> sublayout) = Client sublayout
34 clientWithRoute Proxy req =
35 clientWithRoute (Proxy :: Proxy sublayout) $
36 appendToPath p req
38 where p = symbolVal (Proxy :: Proxy path)