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