diff --git a/src/Servant/Client.hs b/src/Servant/Client.hs index 0a507658..6a0f4f6b 100644 --- a/src/Servant/Client.hs +++ b/src/Servant/Client.hs @@ -13,6 +13,7 @@ module Servant.Client , module Servant.Common.BaseUrl ) where +import Control.Monad import Control.Monad.Trans.Either import Data.Aeson import Data.ByteString.Lazy (ByteString) @@ -108,7 +109,7 @@ instance HasClient Delete where type Client Delete = BaseUrl -> EitherT String IO () clientWithRoute Proxy req host = - performRequestJSON H.methodDelete req 204 host + void $ performRequest H.methodDelete req (== 204) host -- | If you have a 'Get' endpoint in your API, the client -- side querying function that is created when calling 'client' diff --git a/test/Servant/ClientSpec.hs b/test/Servant/ClientSpec.hs index b3e2b263..ced45224 100644 --- a/test/Servant/ClientSpec.hs +++ b/test/Servant/ClientSpec.hs @@ -45,6 +45,7 @@ alice = Person "Alice" 42 type Api = "get" :> Get Person + :<|> "delete" :> Delete :<|> "capture" :> Capture "name" String :> Get Person :<|> "body" :> ReqBody Person :> Post Person :<|> "param" :> QueryParam "name" String :> Get Person @@ -67,6 +68,7 @@ api = Proxy server :: Application server = serve api ( return alice + :<|> return () :<|> (\ name -> return $ Person name 0) :<|> return :<|> (\ name -> case name of @@ -90,6 +92,7 @@ withServer :: (BaseUrl -> IO a) -> IO a withServer action = withWaiDaemon (return server) action getGet :: BaseUrl -> EitherT String IO Person +getDelete :: BaseUrl -> EitherT String IO () getCapture :: String -> BaseUrl -> EitherT String IO Person getBody :: Person -> BaseUrl -> EitherT String IO Person getQueryParam :: Maybe String -> BaseUrl -> EitherT String IO Person @@ -104,6 +107,7 @@ getMultiple :: String -> Maybe Int -> Bool -> [(String, [Rational])] -> BaseUrl -> EitherT String IO (String, Maybe Int, Bool, [(String, [Rational])]) ( getGet + :<|> getDelete :<|> getCapture :<|> getBody :<|> getQueryParam @@ -122,6 +126,9 @@ spec = do it "Servant.API.Get" $ withServer $ \ host -> do runEitherT (getGet host) `shouldReturn` Right alice + it "Servant.API.Delete" $ withServer $ \ host -> do + runEitherT (getDelete host) `shouldReturn` Right () + it "Servant.API.Capture" $ withServer $ \ host -> do runEitherT (getCapture "Paula" host) `shouldReturn` Right (Person "Paula" 0)