@@ -13,8 +13,8 @@ import Network.Wai
1313import Network.Wai.Handler.Warp
1414import Test.Hspec
1515
16−import Servant.Client
1716import Servant.API
17+import Servant.Client
1818import Servant.Server
1919
2020import Servant.ServerSpec
@@ -22,6 +22,7 @@ import Servant.ServerSpec
2222type Api =
2323 "get" :> Get Person
2424 :<|> "capture" :> Capture "name" String :> Get Person
25+ :<|> "body" :> ReqBody Person :> Post Person
2526api :: Proxy Api
2627api = Proxy
2728
@@ -29,22 +30,28 @@ server :: Application
2930server = serve api (
3031 return alice
3132 :<|> (\ name -> return $ Person name 0)
33+ :<|> return
3234 )
3335
3436withServer :: (URIAuth -> IO a) -> IO a
3537withServer action = withWaiDaemon (return server) (action . mkHost "localhost")
3638
37−getA :: URIAuth -> EitherT String IO Person
38−getB :: String -> URIAuth -> EitherT String IO Person
39−(getA :<|> getB) = client api
39+getGet :: URIAuth -> EitherT String IO Person
40+getCapture :: String -> URIAuth -> EitherT String IO Person
41+getBody :: Person -> URIAuth -> EitherT String IO Person
42+(getGet :<|> getCapture :<|> getBody) = client api
4043
4144spec :: Spec
4245spec = do
4346 it "Servant.API.Get" $ withServer $ \ host -> do
44− runEitherT (getA host) `shouldReturn` Right alice
47+ runEitherT (getGet host) `shouldReturn` Right alice
4548
4649 it "Servant.API.Capture" $ withServer $ \ host -> do
47− runEitherT (getB "Paula" host) `shouldReturn` Right (Person "Paula" 0)
50+ runEitherT (getCapture "Paula" host) `shouldReturn` Right (Person "Paula" 0)
51+
52+ it "Servant.API.ReqBody" $ withServer $ \ host -> do
53+ let p = Person "Clara" 42
54+ runEitherT (getBody p host) `shouldReturn` Right p
4855
4956
5057-- * utils