Merge branch 'tvh-delete-empty-body'
This commit is contained in:
commit
6797a58f65
2 changed files with 9 additions and 1 deletions
|
@ -13,6 +13,7 @@ module Servant.Client
|
||||||
, module Servant.Common.BaseUrl
|
, module Servant.Common.BaseUrl
|
||||||
) where
|
) where
|
||||||
|
|
||||||
|
import Control.Monad
|
||||||
import Control.Monad.Trans.Either
|
import Control.Monad.Trans.Either
|
||||||
import Data.Aeson
|
import Data.Aeson
|
||||||
import Data.ByteString.Lazy (ByteString)
|
import Data.ByteString.Lazy (ByteString)
|
||||||
|
@ -108,7 +109,7 @@ instance HasClient Delete where
|
||||||
type Client Delete = BaseUrl -> EitherT String IO ()
|
type Client Delete = BaseUrl -> EitherT String IO ()
|
||||||
|
|
||||||
clientWithRoute Proxy req host =
|
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
|
-- | If you have a 'Get' endpoint in your API, the client
|
||||||
-- side querying function that is created when calling 'client'
|
-- side querying function that is created when calling 'client'
|
||||||
|
|
|
@ -45,6 +45,7 @@ alice = Person "Alice" 42
|
||||||
|
|
||||||
type Api =
|
type Api =
|
||||||
"get" :> Get Person
|
"get" :> Get Person
|
||||||
|
:<|> "delete" :> Delete
|
||||||
:<|> "capture" :> Capture "name" String :> Get Person
|
:<|> "capture" :> Capture "name" String :> Get Person
|
||||||
:<|> "body" :> ReqBody Person :> Post Person
|
:<|> "body" :> ReqBody Person :> Post Person
|
||||||
:<|> "param" :> QueryParam "name" String :> Get Person
|
:<|> "param" :> QueryParam "name" String :> Get Person
|
||||||
|
@ -67,6 +68,7 @@ api = Proxy
|
||||||
server :: Application
|
server :: Application
|
||||||
server = serve api (
|
server = serve api (
|
||||||
return alice
|
return alice
|
||||||
|
:<|> return ()
|
||||||
:<|> (\ name -> return $ Person name 0)
|
:<|> (\ name -> return $ Person name 0)
|
||||||
:<|> return
|
:<|> return
|
||||||
:<|> (\ name -> case name of
|
:<|> (\ name -> case name of
|
||||||
|
@ -90,6 +92,7 @@ withServer :: (BaseUrl -> IO a) -> IO a
|
||||||
withServer action = withWaiDaemon (return server) action
|
withServer action = withWaiDaemon (return server) action
|
||||||
|
|
||||||
getGet :: BaseUrl -> EitherT String IO Person
|
getGet :: BaseUrl -> EitherT String IO Person
|
||||||
|
getDelete :: BaseUrl -> EitherT String IO ()
|
||||||
getCapture :: String -> BaseUrl -> EitherT String IO Person
|
getCapture :: String -> BaseUrl -> EitherT String IO Person
|
||||||
getBody :: Person -> BaseUrl -> EitherT String IO Person
|
getBody :: Person -> BaseUrl -> EitherT String IO Person
|
||||||
getQueryParam :: Maybe String -> 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
|
-> BaseUrl
|
||||||
-> EitherT String IO (String, Maybe Int, Bool, [(String, [Rational])])
|
-> EitherT String IO (String, Maybe Int, Bool, [(String, [Rational])])
|
||||||
( getGet
|
( getGet
|
||||||
|
:<|> getDelete
|
||||||
:<|> getCapture
|
:<|> getCapture
|
||||||
:<|> getBody
|
:<|> getBody
|
||||||
:<|> getQueryParam
|
:<|> getQueryParam
|
||||||
|
@ -122,6 +126,9 @@ spec = do
|
||||||
it "Servant.API.Get" $ withServer $ \ host -> do
|
it "Servant.API.Get" $ withServer $ \ host -> do
|
||||||
runEitherT (getGet host) `shouldReturn` Right alice
|
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
|
it "Servant.API.Capture" $ withServer $ \ host -> do
|
||||||
runEitherT (getCapture "Paula" host) `shouldReturn` Right (Person "Paula" 0)
|
runEitherT (getCapture "Paula" host) `shouldReturn` Right (Person "Paula" 0)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue