1{-# LANGUAGE DataKinds #-}
2{-# LANGUAGE PolyKinds #-}
3{-# LANGUAGE TypeFamilies #-}
4{-# LANGUAGE DeriveGeneric #-}
5{-# LANGUAGE TypeOperators #-}
6{-# LANGUAGE OverloadedStrings #-}
8import Control.Concurrent (forkIO, killThread)
9import Control.Monad.Trans.Either
17import Network.Wai.Handler.Warp
25data Greet = Greet { msg :: Text }
26 deriving (Generic, Show)
28instance FromJSON Greet
33 "hello" :> Capture "name" Text :> GetParam "capital" Bool :> Get Greet
34 :<|> "greet" :> RQBody Greet :> Post Greet
36testApi :: Proxy TestApi
39-- Server-side handlers
40server :: Server TestApi
41server = hello :<|> greet
43 where hello name Nothing = hello name (Just False)
44 hello name (Just False) = return . Greet $ "Hello, " <> name
45 hello name (Just True) = return . Greet . toUpper $ "Hello, " <> name
49-- Client-side query functions
50clientApi :: Client TestApi
51clientApi = client testApi
53getGreet :: Text -> Maybe Bool -> URI -> EitherT String IO Greet
54postGreet :: Greet -> URI -> EitherT String IO Greet
55getGreet :<|> postGreet = clientApi
57-- Turn the server into a WAI app
59test = serve testApi server
62runTestServer :: Port -> IO ()
63runTestServer port = run port test
65-- Run some queries against the server
68 tid <- forkIO $ runTestServer 8001
69 let Just uri = parseURI "http://localhost:8001"
70 print =<< runEitherT (getGreet "alp" (Just True) uri)
71 print =<< runEitherT (getGreet "alp" (Just False) uri)
73 print =<< runEitherT (postGreet g uri)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list