@@ -80,7 +80,7 @@ type TestHeaders = '[Header "X-Example1" Int, Header "X-Example2" String]
82 "get" :> Get '[JSON] Person
82 "get" :> Get '[JSON] Person
83− :<|> "delete" :> Delete '[JSON] ()
83+ :<|> "deleteEmpty" :> Delete '[] ()
84 :<|> "capture" :> Capture "name" String :> Get '[JSON,FormUrlEncoded] Person
84 :<|> "capture" :> Capture "name" String :> Get '[JSON,FormUrlEncoded] Person
85 :<|> "body" :> ReqBody '[FormUrlEncoded,JSON] Person :> Post '[JSON] Person
85 :<|> "body" :> ReqBody '[FormUrlEncoded,JSON] Person :> Post '[JSON] Person
86 :<|> "param" :> QueryParam "name" String :> Get '[FormUrlEncoded,JSON] Person
86 :<|> "param" :> QueryParam "name" String :> Get '[FormUrlEncoded,JSON] Person
@@ -98,6 +98,7 @@ type Api =
98 ReqBody '[JSON] [(String, [Rational])] :>
98 ReqBody '[JSON] [(String, [Rational])] :>
99 Get '[JSON] (String, Maybe Int, Bool, [(String, [Rational])])
99 Get '[JSON] (String, Maybe Int, Bool, [(String, [Rational])])
100 :<|> "headers" :> Get '[JSON] (Headers TestHeaders Bool)
100 :<|> "headers" :> Get '[JSON] (Headers TestHeaders Bool)
101+ :<|> "deleteContentType" :> Delete '[JSON] ()
101api :: Proxy Api
102api :: Proxy Api
102api = Proxy
103api = Proxy
@@ -123,6 +124,7 @@ server = serve api (
123 :<|> (\ _request respond -> respond $ responseLBS badRequest400 [] "rawFailure")
124 :<|> (\ _request respond -> respond $ responseLBS badRequest400 [] "rawFailure")
124 :<|> (\ a b c d -> return (a, b, c, d))
125 :<|> (\ a b c d -> return (a, b, c, d))
125 :<|> (return $ addHeader 1729 $ addHeader "eg2" True)
126 :<|> (return $ addHeader 1729 $ addHeader "eg2" True)
128withServer :: (BaseUrl -> IO a) -> IO a
130withServer :: (BaseUrl -> IO a) -> IO a
@@ -148,7 +150,7 @@ withFailServer action = withWaiDaemon (return failServer) action
148spec :: IO ()
150spec :: IO ()
149spec = withServer $ \ baseUrl -> do
151spec = withServer $ \ baseUrl -> do
150 let getGet :: EitherT ServantError IO Person
152 let getGet :: EitherT ServantError IO Person
151− getDelete :: EitherT ServantError IO ()
153+ getDeleteEmpty :: EitherT ServantError IO ()
152 getCapture :: String -> EitherT ServantError IO Person
154 getCapture :: String -> EitherT ServantError IO Person
153 getBody :: Person -> EitherT ServantError IO Person
155 getBody :: Person -> EitherT ServantError IO Person
154 getQueryParam :: Maybe String -> EitherT ServantError IO Person
156 getQueryParam :: Maybe String -> EitherT ServantError IO Person
@@ -161,8 +163,9 @@ spec = withServer $ \ baseUrl -> do
161 getRawFailure :: Method -> EitherT ServantError IO (Int, ByteString, MediaType, [HTTP.Header], C.Response ByteString)
163 getRawFailure :: Method -> EitherT ServantError IO (Int, ByteString, MediaType, [HTTP.Header], C.Response ByteString)
162 getMultiple :: String -> Maybe Int -> Bool -> [(String, [Rational])] -> EitherT ServantError IO (String, Maybe Int, Bool, [(String, [Rational])])
164 getMultiple :: String -> Maybe Int -> Bool -> [(String, [Rational])] -> EitherT ServantError IO (String, Maybe Int, Bool, [(String, [Rational])])
163 getRespHeaders :: EitherT ServantError IO (Headers TestHeaders Bool)
165 getRespHeaders :: EitherT ServantError IO (Headers TestHeaders Bool)
166+ getDeleteContentType :: EitherT ServantError IO ()
165− :<|> getDelete
168+ :<|> getDeleteEmpty
166 :<|> getCapture
169 :<|> getCapture
167 :<|> getBody
170 :<|> getBody
168 :<|> getQueryParam
171 :<|> getQueryParam
@@ -174,15 +177,20 @@ spec = withServer $ \ baseUrl -> do
174 :<|> getRawSuccess
177 :<|> getRawSuccess
175 :<|> getRawFailure
178 :<|> getRawFailure
176 :<|> getMultiple
179 :<|> getMultiple
177− :<|> getRespHeaders)
180+ :<|> getRespHeaders
181+ :<|> getDeleteContentType)
178 = client api baseUrl
182 = client api baseUrl
180 hspec $ do
184 hspec $ do
181 it "Servant.API.Get" $ do
185 it "Servant.API.Get" $ do
182 (Arrow.left show <$> runEitherT getGet) `shouldReturn` Right alice
186 (Arrow.left show <$> runEitherT getGet) `shouldReturn` Right alice
184− it "Servant.API.Delete" $ do
188+ describe "Servant.API.Delete" $ do
189+ it "allows empty content type" $ do
185− (Arrow.left show <$> runEitherT getDelete) `shouldReturn` Right ()
190+ (Arrow.left show <$> runEitherT getDeleteEmpty) `shouldReturn` Right ()
192+ it "allows content type" $ do
193+ (Arrow.left show <$> runEitherT getDeleteContentType) `shouldReturn` Right ()
187 it "Servant.API.Capture" $ do
195 it "Servant.API.Capture" $ do
188 (Arrow.left show <$> runEitherT (getCapture "Paula")) `shouldReturn` Right (Person "Paula" 0)
196 (Arrow.left show <$> runEitherT (getCapture "Paula")) `shouldReturn` Right (Person "Paula" 0)
@@ -274,11 +282,11 @@ spec = withServer $ \ baseUrl -> do
274failSpec :: IO ()
282failSpec :: IO ()
275failSpec = withFailServer $ \ baseUrl -> do
283failSpec = withFailServer $ \ baseUrl -> do
276 let getGet :: EitherT ServantError IO Person
284 let getGet :: EitherT ServantError IO Person
277− getDelete :: EitherT ServantError IO ()
285+ getDeleteEmpty :: EitherT ServantError IO ()
278 getCapture :: String -> EitherT ServantError IO Person
286 getCapture :: String -> EitherT ServantError IO Person
279 getBody :: Person -> EitherT ServantError IO Person
287 getBody :: Person -> EitherT ServantError IO Person
281− :<|> getDelete
289+ :<|> getDeleteEmpty
282 :<|> getCapture
290 :<|> getCapture
283 :<|> getBody
291 :<|> getBody
@@ -289,7 +297,7 @@ failSpec = withFailServer $ \ baseUrl -> do
289 hspec $ do
297 hspec $ do
290 context "client returns errors appropriately" $ do
298 context "client returns errors appropriately" $ do
291 it "reports FailureResponse" $ do
299 it "reports FailureResponse" $ do
292− Left res <- runEitherT getDelete
300+ Left res <- runEitherT getDeleteEmpty
293 case res of
301 case res of
294 FailureResponse (Status 404 "Not Found") _ _ -> return ()
302 FailureResponse (Status 404 "Not Found") _ _ -> return ()
295 _ -> fail $ "expected 404 response, but got " <> show res
303 _ -> fail $ "expected 404 response, but got " <> show res