diff --git a/src/Servant/Server.hs b/src/Servant/Server.hs index d1d6e4c4..d8661585 100644 --- a/src/Servant/Server.hs +++ b/src/Servant/Server.hs @@ -29,6 +29,9 @@ import Servant.Server.Internal -- > where listAllBooks = ... -- > postBook book = ... -- > +-- > myApi :: Proxy MyApi +-- > myApi = Proxy +-- > -- > app :: Application -- > app = serve myApi server -- > diff --git a/test/Servant/ServerSpec.hs b/test/Servant/ServerSpec.hs index 38313136..de802670 100644 --- a/test/Servant/ServerSpec.hs +++ b/test/Servant/ServerSpec.hs @@ -189,19 +189,26 @@ queryParamSpec = do name = "ALICE" } -type PostApi = ReqBody Person :> Post Integer +type PostApi = + ReqBody Person :> Post Integer + :<|> "bla" :> ReqBody Person :> Post Integer postApi :: Proxy PostApi postApi = Proxy postSpec :: Spec postSpec = do describe "Servant.API.Post and .ReqBody" $ do - with (return (serve postApi (return . age))) $ do + with (return (serve postApi (return . age :<|> return . age))) $ do it "allows to POST a Person" $ do post "/" (encode alice) `shouldRespondWith` "42"{ matchStatus = 201 } + it "allows alternative routes if all have request bodies" $ do + post "/bla" (encode alice) `shouldRespondWith` "42"{ + matchStatus = 201 + } + it "correctly rejects invalid request bodies with status 400" $ do post "/" "some invalid body" `shouldRespondWith` 400