on master help sign in
Merge branch 'tvh-delete-empty-body'
6797a58Christian Marie
src/Servant/Client.hs+2−1
@@ -13,6 +13,7 @@ module Servant.Client
13 , module Servant.Common.BaseUrl
13 , module Servant.Common.BaseUrl
14 ) where
14 ) where
15
15
16+import Control.Monad
16import Control.Monad.Trans.Either
17import Control.Monad.Trans.Either
17import Data.Aeson
18import Data.Aeson
18import Data.ByteString.Lazy (ByteString)
19import Data.ByteString.Lazy (ByteString)
@@ -108,7 +109,7 @@ instance HasClient Delete where
108 type Client Delete = BaseUrl -> EitherT String IO ()
109 type Client Delete = BaseUrl -> EitherT String IO ()
109
110
110 clientWithRoute Proxy req host =
111 clientWithRoute Proxy req host =
111− performRequestJSON H.methodDelete req 204 host
112+ void $ performRequest H.methodDelete req (== 204) host
112
113
113-- | If you have a 'Get' endpoint in your API, the client
114-- | If you have a 'Get' endpoint in your API, the client
114-- side querying function that is created when calling 'client'
115-- side querying function that is created when calling 'client'
test/Servant/ClientSpec.hs+7
@@ -45,6 +45,7 @@ alice = Person "Alice" 42
45
45
46type Api =
46type Api =
47 "get" :> Get Person
47 "get" :> Get Person
48+ :<|> "delete" :> Delete
48 :<|> "capture" :> Capture "name" String :> Get Person
49 :<|> "capture" :> Capture "name" String :> Get Person
49 :<|> "body" :> ReqBody Person :> Post Person
50 :<|> "body" :> ReqBody Person :> Post Person
50 :<|> "param" :> QueryParam "name" String :> Get Person
51 :<|> "param" :> QueryParam "name" String :> Get Person
@@ -67,6 +68,7 @@ api = Proxy
67server :: Application
68server :: Application
68server = serve api (
69server = serve api (
69 return alice
70 return alice
71+ :<|> return ()
70 :<|> (\ name -> return $ Person name 0)
72 :<|> (\ name -> return $ Person name 0)
71 :<|> return
73 :<|> return
72 :<|> (\ name -> case name of
74 :<|> (\ name -> case name of
@@ -90,6 +92,7 @@ withServer :: (BaseUrl -> IO a) -> IO a
90withServer action = withWaiDaemon (return server) action
92withServer action = withWaiDaemon (return server) action
91
93
92getGet :: BaseUrl -> EitherT String IO Person
94getGet :: BaseUrl -> EitherT String IO Person
95+getDelete :: BaseUrl -> EitherT String IO ()
93getCapture :: String -> BaseUrl -> EitherT String IO Person
96getCapture :: String -> BaseUrl -> EitherT String IO Person
94getBody :: Person -> BaseUrl -> EitherT String IO Person
97getBody :: Person -> BaseUrl -> EitherT String IO Person
95getQueryParam :: Maybe String -> BaseUrl -> EitherT String IO Person
98getQueryParam :: Maybe String -> BaseUrl -> EitherT String IO Person
@@ -104,6 +107,7 @@ getMultiple :: String -> Maybe Int -> Bool -> [(String, [Rational])]
104 -> BaseUrl
107 -> BaseUrl
105 -> EitherT String IO (String, Maybe Int, Bool, [(String, [Rational])])
108 -> EitherT String IO (String, Maybe Int, Bool, [(String, [Rational])])
106( getGet
109( getGet
110+ :<|> getDelete
107 :<|> getCapture
111 :<|> getCapture
108 :<|> getBody
112 :<|> getBody
109 :<|> getQueryParam
113 :<|> getQueryParam
@@ -122,6 +126,9 @@ spec = do
122 it "Servant.API.Get" $ withServer $ \ host -> do
126 it "Servant.API.Get" $ withServer $ \ host -> do
123 runEitherT (getGet host) `shouldReturn` Right alice
127 runEitherT (getGet host) `shouldReturn` Right alice
124
128
129+ it "Servant.API.Delete" $ withServer $ \ host -> do
130+ runEitherT (getDelete host) `shouldReturn` Right ()
131+
125 it "Servant.API.Capture" $ withServer $ \ host -> do
132 it "Servant.API.Capture" $ withServer $ \ host -> do
126 runEitherT (getCapture "Paula" host) `shouldReturn` Right (Person "Paula" 0)
133 runEitherT (getCapture "Paula" host) `shouldReturn` Right (Person "Paula" 0)
127
134