@@ -34,6 +34,9 @@ instance ToJSON Greet
34instance ToCapture (Capture "name" Text) where
34instance ToCapture (Capture "name" Text) where
35 toCapture _ = DocCapture "name" "name of the person to greet"
35 toCapture _ = DocCapture "name" "name of the person to greet"
37+instance ToCapture (Capture "greetid" Text) where
38+ toCapture _ = DocCapture "greetid" "identifier of the greet msg to remove"
37instance ToParam (GetParam "capital" Bool) where
40instance ToParam (GetParam "capital" Bool) where
38 toParam _ =
41 toParam _ =
39 DocGetParam "capital"
42 DocGetParam "capital"
@@ -49,13 +52,14 @@ instance ToSample Greet where
49type TestApi =
52type TestApi =
50 "hello" :> Capture "name" Text :> GetParam "capital" Bool :> Get Greet
53 "hello" :> Capture "name" Text :> GetParam "capital" Bool :> Get Greet
51 :<|> "greet" :> RQBody Greet :> Post Greet
54 :<|> "greet" :> RQBody Greet :> Post Greet
55+ :<|> "delete" :> Capture "greetid" Text :> Delete
53testApi :: Proxy TestApi
57testApi :: Proxy TestApi
54testApi = Proxy
58testApi = Proxy
56-- Server-side handlers
60-- Server-side handlers
57server :: Server TestApi
61server :: Server TestApi
58−server = hello :<|> greet
62+server = hello :<|> greet :<|> delete
60 where hello name Nothing = hello name (Just False)
64 where hello name Nothing = hello name (Just False)
61 hello name (Just False) = return . Greet $ "Hello, " <> name
65 hello name (Just False) = return . Greet $ "Hello, " <> name
@@ -63,18 +67,22 @@ server = hello :<|> greet
64 greet = return
68 greet = return
66-- Client-side query functions
72-- Client-side query functions
67clientApi :: Client TestApi
73clientApi :: Client TestApi
68clientApi = client testApi
74clientApi = client testApi
70getGreet :: Text -> Maybe Bool -> URI -> EitherT String IO Greet
76getGreet :: Text -> Maybe Bool -> URI -> EitherT String IO Greet
71postGreet :: Greet -> URI -> EitherT String IO Greet
77postGreet :: Greet -> URI -> EitherT String IO Greet
78+deleteGreet :: Text -> URI -> EitherT String IO ()
72−getGreet :<|> postGreet = clientApi
79+getGreet :<|> postGreet :<|> deleteGreet = clientApi
74-- Turn the server into a WAI app
81-- Turn the server into a WAI app
75test :: Application
82test :: Application
76test = serve testApi server
83test = serve testApi server
78docsGreet :: API
86docsGreet :: API
79docsGreet = docs testApi
87docsGreet = docs testApi
@@ -91,6 +99,7 @@ main = do
91 print =<< runEitherT (getGreet "alp" (Just False) uri)
99 print =<< runEitherT (getGreet "alp" (Just False) uri)
92 let g = Greet "yo"
100 let g = Greet "yo"
93 print =<< runEitherT (postGreet g uri)
101 print =<< runEitherT (postGreet g uri)
102+ print =<< runEitherT (deleteGreet "blah" uri)
94 killThread tid
103 killThread tid
95 putStrLn "\n---------\n"
104 putStrLn "\n---------\n"
96 printMarkdown docsGreet
105 printMarkdown docsGreet