git.iko.soy/typeable/servant
on feef8ca help sign in
49 lines 1.4 kB history raw
1{-# LANGUAGE DataKinds #-}
2{-# LANGUAGE TypeFamilies #-}
3{-# LANGUAGE TypeOperators #-}
4module T8 where
6import Control.Monad.Trans.Except
7import Network.HTTP.Client (Manager, defaultManagerSettings,
8 newManager)
9import Servant
10import Servant.Client
11import System.IO.Unsafe (unsafePerformIO)
13import T3
15position :: Int -- ^ value for "x"
16 -> Int -- ^ value for "y"
17 -> ExceptT ServantError IO Position
19hello :: Maybe String -- ^ an optional value for "name"
20 -> ExceptT ServantError IO HelloMessage
22marketing :: ClientInfo -- ^ value for the request body
23 -> ExceptT ServantError IO Email
25position :<|> hello :<|> marketing = client api baseUrl manager
27baseUrl :: BaseUrl
28baseUrl = BaseUrl Http "localhost" 8081 ""
30{-# NOINLINE manager #-}
31manager :: Manager
32manager = unsafePerformIO $ newManager defaultManagerSettings
34queries :: ExceptT ServantError IO (Position, HelloMessage, Email)
35queries = do
36 pos <- position 10 10
37 msg <- hello (Just "servant")
38 em <- marketing (ClientInfo "Alp" "alp@foo.com" 26 ["haskell", "mathematics"])
39 return (pos, msg, em)
41run :: IO ()
42run = do
43 res <- runExceptT queries
44 case res of
45 Left err -> putStrLn $ "Error: " ++ show err
46 Right (pos, msg, em) -> do
47 print pos
48 print msg
49 print em