on 404bfdd help sign in
43 lines 1.1 kB history raw
1{-# LANGUAGE DataKinds #-}
2{-# LANGUAGE TypeFamilies #-}
3{-# LANGUAGE TypeOperators #-}
4module T8 where
6import Control.Monad.Trans.Either
7import Data.Aeson
8import Servant
9import Servant.Client
11import T3
13position :: Int -- ^ value for "x"
14 -> Int -- ^ value for "y"
15 -> EitherT ServantError IO Position
17hello :: Maybe String -- ^ an optional value for "name"
18 -> EitherT ServantError IO HelloMessage
20marketing :: ClientInfo -- ^ value for the request body
21 -> EitherT ServantError IO Email
23position :<|> hello :<|> marketing = client api baseUrl
25baseUrl :: BaseUrl
26baseUrl = BaseUrl Http "localhost" 8081
28queries :: EitherT ServantError IO (Position, HelloMessage, Email)
29queries = do
30 pos <- position 10 10
31 msg <- hello (Just "servant")
32 em <- marketing (ClientInfo "Alp" "alp@foo.com" 26 ["haskell", "mathematics"])
33 return (pos, msg, em)
35run :: IO ()
36run = do
37 res <- runEitherT queries
38 case res of
39 Left err -> putStrLn $ "Error: " ++ show err
40 Right (pos, msg, em) -> do
41 print pos
42 print msg
43 print em