on master help sign in
examples: add GS7
c892aaeAlp Mestanogullari
servant-examples/getting-started/GS7.hsnew file+33
@@ -0,0 +1,33 @@
1+{-# LANGUAGE DataKinds #-}
2+{-# LANGUAGE TypeFamilies #-}
3+{-# LANGUAGE TypeOperators #-}
4+module GS7 where
5+
6+import Control.Monad.Trans.Either
7+import Control.Monad.Trans.Reader
8+import Network.Wai
9+import Servant
10+
11+type ReaderAPI = "a" :> Get '[JSON] Int
12+ :<|> "b" :> Get '[JSON] String
13+
14+readerAPI :: Proxy ReaderAPI
15+readerAPI = Proxy
16+
17+readerServerT :: ServerT ReaderAPI (Reader String)
18+readerServerT = a :<|> b
19+
20+ where a :: Reader String Int
21+ a = return 1797
22+
23+ b :: Reader String String
24+ b = ask
25+
26+readerServer :: Server ReaderAPI
27+readerServer = enter readerToEither readerServerT
28+
29+ where readerToEither :: Reader String :~> EitherT ServantErr IO
30+ readerToEither = Nat $ \r -> return (runReader r "hi")
31+
32+app :: Application
33+app = serve readerAPI readerServer
servant-examples/getting-started/getting-started.hs+2
@@ -8,6 +8,7 @@ import qualified GS3
8import qualified GS4
8import qualified GS4
9import qualified GS5
9import qualified GS5
10import qualified GS6
10import qualified GS6
11+import qualified GS7
11
12
12app :: String -> Maybe Application
13app :: String -> Maybe Application
13app n = case n of
14app n = case n of
@@ -17,6 +18,7 @@ app n = case n of
17 "4" -> Just GS4.app
18 "4" -> Just GS4.app
18 "5" -> Just GS5.app
19 "5" -> Just GS5.app
19 "6" -> Just GS6.app
20 "6" -> Just GS6.app
21+ "7" -> Just GS7.app
20 _ -> Nothing
22 _ -> Nothing
21
23
22main :: IO ()
24main :: IO ()