@@ -13,8 +13,8 @@ import Network.Wai
13import Network.Wai.Handler.Warp
13import Network.Wai.Handler.Warp
14import Test.Hspec
14import Test.Hspec
17import Servant.API
16import Servant.API
18import Servant.Server
18import Servant.Server
20import Servant.ServerSpec
20import Servant.ServerSpec
@@ -22,6 +22,7 @@ import Servant.ServerSpec
23 "get" :> Get Person
23 "get" :> Get Person
24 :<|> "capture" :> Capture "name" String :> Get Person
24 :<|> "capture" :> Capture "name" String :> Get Person
25+ :<|> "body" :> ReqBody Person :> Post Person
25api :: Proxy Api
26api :: Proxy Api
26api = Proxy
27api = Proxy
@@ -29,22 +30,28 @@ server :: Application
29server = serve api (
30server = serve api (
30 return alice
31 return alice
31 :<|> (\ name -> return $ Person name 0)
32 :<|> (\ name -> return $ Person name 0)
34withServer :: (URIAuth -> IO a) -> IO a
36withServer :: (URIAuth -> IO a) -> IO a
35withServer action = withWaiDaemon (return server) (action . mkHost "localhost")
37withServer action = withWaiDaemon (return server) (action . mkHost "localhost")
37−getA :: URIAuth -> EitherT String IO Person
39+getGet :: URIAuth -> EitherT String IO Person
38−getB :: String -> URIAuth -> EitherT String IO Person
40+getCapture :: String -> URIAuth -> EitherT String IO Person
39−(getA :<|> getB) = client api
41+getBody :: Person -> URIAuth -> EitherT String IO Person
42+(getGet :<|> getCapture :<|> getBody) = client api
41spec :: Spec
44spec :: Spec
43 it "Servant.API.Get" $ withServer $ \ host -> do
46 it "Servant.API.Get" $ withServer $ \ host -> do
44− runEitherT (getA host) `shouldReturn` Right alice
47+ runEitherT (getGet host) `shouldReturn` Right alice
46 it "Servant.API.Capture" $ withServer $ \ host -> do
49 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)
52+ it "Servant.API.ReqBody" $ withServer $ \ host -> do
53+ let p = Person "Clara" 42
54+ runEitherT (getBody p host) `shouldReturn` Right p