1{-# LANGUAGE DataKinds #-}
2{-# LANGUAGE PolyKinds #-}
3{-# LANGUAGE TypeFamilies #-}
4{-# LANGUAGE DeriveGeneric #-}
5{-# LANGUAGE TypeOperators #-}
6{-# LANGUAGE OverloadedStrings #-}
14import Network.Wai.Handler.Warp
20-- | A greet message data type
21newtype Greet = Greet { _msg :: Text }
22 deriving (Generic, Show)
24instance FromJSON Greet
29 -- GET /hello/:name?capital={true, false} returns a Greet as JSON
30 "hello" :> Capture "name" Text :> QueryParam "capital" Bool :> Get '[JSON] Greet
32 -- POST /greet with a Greet as JSON in the request body,
33 -- returns a Greet as JSON
34 :<|> "greet" :> ReqBody '[JSON] Greet :> Post '[JSON] Greet
36 -- DELETE /greet/:greetid
37 :<|> "greet" :> Capture "greetid" Text :> Delete
39testApi :: Proxy TestApi
42-- Server-side handlers.
44-- There's one handler per endpoint, which, just like in the type
45-- that represents the API, are glued together using :<|>.
47-- Each handler runs in the 'EitherT (Int, String) IO' monad.
48server :: Server TestApi
49server = helloH :<|> postGreetH :<|> deleteGreetH
51 where helloH name Nothing = helloH name (Just False)
52 helloH name (Just False) = return . Greet $ "Hello, " <> name
53 helloH name (Just True) = return . Greet . toUpper $ "Hello, " <> name
55 postGreetH greet = return greet
57 deleteGreetH _ = return ()
59-- Turn the server into a WAI app. 'serve' is provided by servant,
60-- more precisely by the Servant.Server module.
62test = serve testApi server
66-- 'run' comes from Network.Wai.Handler.Warp
67runTestServer :: Port -> IO ()
68runTestServer port = run port test
70-- Put this all to work!
72main = runTestServer 8001
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