@@ -34,6 +34,9 @@ instance ToJSON Greet
3434instance ToCapture (Capture "name" Text) where
3535 toCapture _ = DocCapture "name" "name of the person to greet"
3636
37+instance ToCapture (Capture "greetid" Text) where
38+ toCapture _ = DocCapture "greetid" "identifier of the greet msg to remove"
39+
3740instance ToParam (GetParam "capital" Bool) where
3841 toParam _ =
3942 DocGetParam "capital"
@@ -49,13 +52,14 @@ instance ToSample Greet where
4952type TestApi =
5053 "hello" :> Capture "name" Text :> GetParam "capital" Bool :> Get Greet
5154 :<|> "greet" :> RQBody Greet :> Post Greet
55+ :<|> "delete" :> Capture "greetid" Text :> Delete
5256
5357testApi :: Proxy TestApi
5458testApi = Proxy
5559
5660-- Server-side handlers
5761server :: Server TestApi
58−server = hello :<|> greet
62+server = hello :<|> greet :<|> delete
5963
6064 where hello name Nothing = hello name (Just False)
6165 hello name (Just False) = return . Greet $ "Hello, " <> name
@@ -63,18 +67,22 @@ server = hello :<|> greet
6367
6468 greet = return
6569
70+ delete _ = return ()
71+
6672-- Client-side query functions
6773clientApi :: Client TestApi
6874clientApi = client testApi
6975
7076getGreet :: Text -> Maybe Bool -> URI -> EitherT String IO Greet
7177postGreet :: Greet -> URI -> EitherT String IO Greet
72−getGreet :<|> postGreet = clientApi
78+deleteGreet :: Text -> URI -> EitherT String IO ()
79+getGreet :<|> postGreet :<|> deleteGreet = clientApi
7380
7481-- Turn the server into a WAI app
7582test :: Application
7683test = serve testApi server
7784
85+-- Documentation
7886docsGreet :: API
7987docsGreet = docs testApi
8088
@@ -91,6 +99,7 @@ main = do
9199 print =<< runEitherT (getGreet "alp" (Just False) uri)
92100 let g = Greet "yo"
93101 print =<< runEitherT (postGreet g uri)
102+ print =<< runEitherT (deleteGreet "blah" uri)
94103 killThread tid
95104 putStrLn "\n---------\n"
96105 printMarkdown docsGreet