@@ -13,15 +13,18 @@ import Data.Proxy
13import GHC.Generics
13import GHC.Generics
14import Network.Wai.Test
14import Network.Wai.Test
15import Test.Hspec
15import Test.Hspec
16−import Test.Hspec.Wai
16+import Test.Hspec.Wai as Wai
18import Servant.API.Get
18import Servant.API.Get
19import Servant.API.Post
19import Servant.API.Post
20import Servant.API.RQBody
20import Servant.API.RQBody
21import Servant.API.Sub
21import Servant.API.Sub
22+import Servant.API.Union
22import Servant.Server
23import Servant.Server
25data Person = Person {
28data Person = Person {
26 name :: String,
29 name :: String,
27 age :: Integer
30 age :: Integer
@@ -34,11 +37,26 @@ instance FromJSON Person
34alice :: Person
37alice :: Person
35alice = Person "Alice" 42
38alice = Person "Alice" 42
40+data Animal = Animal {
42+ numberOfLegs :: Integer
44+ deriving (Eq, Show, Generic)
46+instance ToJSON Animal
47+instance FromJSON Animal
50+jerry = Animal "Mouse" 4
38spec :: Spec
55spec :: Spec
44type GetApi = Get Person
62type GetApi = Get Person
@@ -70,3 +88,29 @@ postSpec = do
70 post "/" (encode alice) `shouldRespondWith` "42"{
88 post "/" (encode alice) `shouldRespondWith` "42"{
71 matchStatus = 201
89 matchStatus = 201
95+ :<|> "bar" :> Get Animal
96+unionApi :: Proxy UnionApi
99+unionServer :: Server UnionApi
106+ describe "Servant.API.Union" $ do
107+ with (return $ serve unionApi unionServer) $ do
108+ it "unions endpoints" $ do
109+ response <- get "/foo"
111+ decode' (simpleBody response) `shouldBe`
113+ response <- get "/bar"
115+ decode' (simpleBody response) `shouldBe`