on master help sign in
Add 'serveWithConfig'.
f137972Julian K. Arni
servant-client/test/Servant/ClientSpec.hs+3−3
@@ -115,7 +115,7 @@ api :: Proxy Api
115api = Proxy
115api = Proxy
116
116
117server :: Application
117server :: Application
118−server = serve api EmptyConfig (
118+server = serve api (
119 return alice
119 return alice
120 :<|> return NoContent
120 :<|> return NoContent
121 :<|> (\ name -> return $ Person name 0)
121 :<|> (\ name -> return $ Person name 0)
@@ -142,7 +142,7 @@ failApi :: Proxy FailApi
142failApi = Proxy
142failApi = Proxy
143
143
144failServer :: Application
144failServer :: Application
145−failServer = serve failApi EmptyConfig (
145+failServer = serve failApi (
146 (\ _request respond -> respond $ responseLBS ok200 [] "")
146 (\ _request respond -> respond $ responseLBS ok200 [] "")
147 :<|> (\ _capture _request respond -> respond $ responseLBS ok200 [("content-type", "application/json")] "")
147 :<|> (\ _capture _request respond -> respond $ responseLBS ok200 [("content-type", "application/json")] "")
148 :<|> (\_request respond -> respond $ responseLBS ok200 [("content-type", "fooooo")] "")
148 :<|> (\_request respond -> respond $ responseLBS ok200 [("content-type", "fooooo")] "")
@@ -232,7 +232,7 @@ sucessSpec = beforeAll (startWaiApp server) $ afterAll endWaiApp $ do
232
232
233wrappedApiSpec :: Spec
233wrappedApiSpec :: Spec
234wrappedApiSpec = describe "error status codes" $ do
234wrappedApiSpec = describe "error status codes" $ do
235− let serveW api = serve api EmptyConfig $ throwE $ ServantErr 500 "error message" "" []
235+ let serveW api = serve api $ throwE $ ServantErr 500 "error message" "" []
236 context "are correctly handled by the client" $
236 context "are correctly handled by the client" $
237 let test :: (WrappedApi, String) -> Spec
237 let test :: (WrappedApi, String) -> Spec
238 test (WrappedApi api, desc) =
238 test (WrappedApi api, desc) =
servant-examples/auth-combinator/auth-combinator.hs+1−1
@@ -82,7 +82,7 @@ main :: IO ()
82main = do
82main = do
83 dbConnection <- initDB
83 dbConnection <- initDB
84 let config = dbConnection :. EmptyConfig
84 let config = dbConnection :. EmptyConfig
85− run 8080 (serve api config server)
85+ run 8080 (serveWithConfig api config server)
86
86
87{- Sample session:
87{- Sample session:
88$ curl http://localhost:8080/
88$ curl http://localhost:8080/
servant-examples/socket-io-chat/socket-io-chat.hs+1−1
@@ -38,7 +38,7 @@ server sHandler = socketIOHandler
38
38
39
39
40app :: WaiMonad () -> Application
40app :: WaiMonad () -> Application
41−app sHandler = serve api EmptyConfig $ server sHandler
41+app sHandler = serve api $ server sHandler
42
42
43port :: Int
43port :: Int
44port = 3001
44port = 3001
servant-examples/tutorial/T1.hs+1−1
@@ -42,4 +42,4 @@ server :: Server UserAPI
42server = return users
42server = return users
43
43
44app :: Application
44app :: Application
45−app = serve userAPI EmptyConfig server
45+app = serve userAPI server
servant-examples/tutorial/T10.hs+1−1
@@ -68,4 +68,4 @@ server = T3.server :<|> serveDocs
68 plain = ("Content-Type", "text/plain")
68 plain = ("Content-Type", "text/plain")
69
69
70app :: Application
70app :: Application
71−app = serve api EmptyConfig server
71+app = serve api server
servant-examples/tutorial/T2.hs+1−1
@@ -49,4 +49,4 @@ server = return users
49 :<|> return isaac
49 :<|> return isaac
50
50
51app :: Application
51app :: Application
52−app = serve userAPI EmptyConfig server
52+app = serve userAPI server
servant-examples/tutorial/T3.hs+1−1
@@ -81,4 +81,4 @@ server = position
81 marketing clientinfo = return (emailForClient clientinfo)
81 marketing clientinfo = return (emailForClient clientinfo)
82
82
83app :: Application
83app :: Application
84−app = serve api EmptyConfig server
84+app = serve api server
servant-examples/tutorial/T4.hs+1−1
@@ -60,4 +60,4 @@ server :: Server PersonAPI
60server = return persons
60server = return persons
61
61
62app :: Application
62app :: Application
63−app = serve personAPI EmptyConfig server
63+app = serve personAPI server
servant-examples/tutorial/T5.hs+1−1
@@ -34,4 +34,4 @@ server = do
34 where custom404Err = err404 { errBody = "myfile.txt just isn't there, please leave this server alone." }
34 where custom404Err = err404 { errBody = "myfile.txt just isn't there, please leave this server alone." }
35
35
36app :: Application
36app :: Application
37−app = serve ioAPI EmptyConfig server
37+app = serve ioAPI server
servant-examples/tutorial/T6.hs+1−1
@@ -15,4 +15,4 @@ server :: Server API
15server = serveDirectory "tutorial"
15server = serveDirectory "tutorial"
16
16
17app :: Application
17app :: Application
18−app = serve api EmptyConfig server
18+app = serve api server
servant-examples/tutorial/T7.hs+1−1
@@ -30,4 +30,4 @@ readerServer = enter readerToEither readerServerT
30 readerToEither = Nat $ \r -> return (runReader r "hi")
30 readerToEither = Nat $ \r -> return (runReader r "hi")
31
31
32app :: Application
32app :: Application
33−app = serve readerAPI EmptyConfig readerServer
33+app = serve readerAPI readerServer
servant-examples/tutorial/T9.hs+1−1
@@ -102,4 +102,4 @@ writeJSFiles = do
102 TIO.writeFile "tutorial/t9/jq.js" jq
102 TIO.writeFile "tutorial/t9/jq.js" jq
103
103
104app :: Application
104app :: Application
105−app = serve api' EmptyConfig server'
105+app = serve api' server'
servant-examples/wai-middleware/wai-middleware.hs+1−1
@@ -45,7 +45,7 @@ server = return products
45-- so applying a middleware is really as simple as
45-- so applying a middleware is really as simple as
46-- applying a function to the result of 'serve'
46-- applying a function to the result of 'serve'
47app :: Application
47app :: Application
48−app = logStdout (serve simpleAPI EmptyConfig server)
48+app = logStdout (serve simpleAPI server)
49
49
50main :: IO ()
50main :: IO ()
51main = run 8080 app
51main = run 8080 app
servant-mock/example/main.hs+1−1
@@ -20,4 +20,4 @@ api :: Proxy API
20api = Proxy
20api = Proxy
21
21
22main :: IO ()
22main :: IO ()
23−main = run 8080 (serve api EmptyConfig $ mock api Proxy)
23+main = run 8080 (serve api $ mock api Proxy)
servant-mock/src/Servant/Mock.hs+8−9
@@ -1,12 +1,12 @@
1−{-# LANGUAGE CPP #-}
1+{-# LANGUAGE CPP #-}
2−{-# LANGUAGE DataKinds #-}
2+{-# LANGUAGE DataKinds #-}
3−{-# LANGUAGE FlexibleContexts #-}
3+{-# LANGUAGE FlexibleContexts #-}
4−{-# LANGUAGE FlexibleInstances #-}
4+{-# LANGUAGE FlexibleInstances #-}
5{-# LANGUAGE MultiParamTypeClasses #-}
5{-# LANGUAGE MultiParamTypeClasses #-}
6−{-# LANGUAGE PolyKinds #-}
6+{-# LANGUAGE PolyKinds #-}
7−{-# LANGUAGE ScopedTypeVariables #-}
7+{-# LANGUAGE ScopedTypeVariables #-}
8−{-# LANGUAGE TypeFamilies #-}
8+{-# LANGUAGE TypeFamilies #-}
9−{-# LANGUAGE TypeOperators #-}
9+{-# LANGUAGE TypeOperators #-}
10{-# OPTIONS_GHC -fno-warn-orphans #-}
10{-# OPTIONS_GHC -fno-warn-orphans #-}
11
11
12#include "overlapping-compat.h"
12#include "overlapping-compat.h"
@@ -67,7 +67,6 @@ import Network.HTTP.Types.Status
67import Network.Wai
67import Network.Wai
68import Servant
68import Servant
69import Servant.API.ContentTypes
69import Servant.API.ContentTypes
70−import Servant.Server.Internal.Config
71import Test.QuickCheck.Arbitrary (Arbitrary (..), vector)
70import Test.QuickCheck.Arbitrary (Arbitrary (..), vector)
72import Test.QuickCheck.Gen (Gen, generate)
71import Test.QuickCheck.Gen (Gen, generate)
73
72
servant-mock/test/Servant/MockSpec.hs+2−2
@@ -52,7 +52,7 @@ spec = do
52 context "Get" $ do
52 context "Get" $ do
53 let api :: Proxy (Get '[JSON] Body)
53 let api :: Proxy (Get '[JSON] Body)
54 api = Proxy
54 api = Proxy
55− app = serve api EmptyConfig (mock api Proxy)
55+ app = serve api (mock api Proxy)
56 with (return app) $ do
56 with (return app) $ do
57 it "serves arbitrary response bodies" $ do
57 it "serves arbitrary response bodies" $ do
58 get "/" `shouldRespondWith` 200{
58 get "/" `shouldRespondWith` 200{
@@ -65,7 +65,7 @@ spec = do
65 withoutHeader :: Proxy (Get '[JSON] (Headers '[] Body))
65 withoutHeader :: Proxy (Get '[JSON] (Headers '[] Body))
66 withoutHeader = Proxy
66 withoutHeader = Proxy
67 toApp :: (HasMock api '[]) => Proxy api -> IO Application
67 toApp :: (HasMock api '[]) => Proxy api -> IO Application
68− toApp api = return $ serve api EmptyConfig (mock api (Proxy :: Proxy '[]))
68+ toApp api = return $ serve api (mock api (Proxy :: Proxy '[]))
69 with (toApp withHeader) $ do
69 with (toApp withHeader) $ do
70 it "serves arbitrary response bodies" $ do
70 it "serves arbitrary response bodies" $ do
71 get "/" `shouldRespondWith` 200{
71 get "/" `shouldRespondWith` 200{
servant-server/example/greet.hs+1−1
@@ -59,7 +59,7 @@ server = helloH :<|> postGreetH :<|> deleteGreetH
59-- Turn the server into a WAI app. 'serve' is provided by servant,
59-- Turn the server into a WAI app. 'serve' is provided by servant,
60-- more precisely by the Servant.Server module.
60-- more precisely by the Servant.Server module.
61test :: Application
61test :: Application
62−test = serve testApi EmptyConfig server
62+test = serve testApi server
63
63
64-- Run the server.
64-- Run the server.
65--
65--
servant-server/src/Servant/Server.hs+8−6
@@ -1,4 +1,5 @@
1{-# LANGUAGE ConstraintKinds #-}
1{-# LANGUAGE ConstraintKinds #-}
2+{-# LANGUAGE DataKinds #-}
2{-# LANGUAGE FlexibleContexts #-}
3{-# LANGUAGE FlexibleContexts #-}
3{-# LANGUAGE OverloadedStrings #-}
4{-# LANGUAGE OverloadedStrings #-}
4{-# LANGUAGE TypeFamilies #-}
5{-# LANGUAGE TypeFamilies #-}
@@ -8,6 +9,7 @@
8module Servant.Server
9module Servant.Server
9 ( -- * Run a wai application from an API
10 ( -- * Run a wai application from an API
10 serve
11 serve
12+ , serveWithConfig
11
13
12 , -- * Construct a wai Application from an API
14 , -- * Construct a wai Application from an API
13 toApplication
15 toApplication
@@ -104,18 +106,18 @@ import Servant.Server.Internal.Enter
104-- > myApi :: Proxy MyApi
106-- > myApi :: Proxy MyApi
105-- > myApi = Proxy
107-- > myApi = Proxy
106-- >
108-- >
107−-- > config :: Config '[]
108−-- > config = EmptyConfig
109−-- >
110-- > app :: Application
109-- > app :: Application
111−-- > app = serve myApi config server
110+-- > app = serve myApi server
112-- >
111-- >
113-- > main :: IO ()
112-- > main :: IO ()
114-- > main = Network.Wai.Handler.Warp.run 8080 app
113-- > main = Network.Wai.Handler.Warp.run 8080 app
115--
114--
116−serve :: (HasServer layout config)
115+serve :: (HasServer layout '[]) => Proxy layout -> Server layout -> Application
116+serve p = serveWithConfig p EmptyConfig
117+
118+serveWithConfig :: (HasServer layout config)
117 => Proxy layout -> Config config -> Server layout -> Application
119 => Proxy layout -> Config config -> Server layout -> Application
118−serve p config server = toApplication (runRouter (route p config d))
120+serveWithConfig p config server = toApplication (runRouter (route p config d))
119 where
121 where
120 d = Delayed r r r (\ _ _ -> Route server)
122 d = Delayed r r r (\ _ _ -> Route server)
121 r = return (Route ())
123 r = return (Route ())
servant-server/src/Servant/Server/Internal/RoutingApplication.hs+1−7
@@ -11,14 +11,8 @@ module Servant.Server.Internal.RoutingApplication where
11import Control.Applicative ((<$>))
11import Control.Applicative ((<$>))
12#endif
12#endif
13import Control.Monad.Trans.Except (ExceptT, runExceptT)
13import Control.Monad.Trans.Except (ExceptT, runExceptT)
14−import qualified Data.ByteString as B
15−import qualified Data.ByteString.Lazy as BL
16−import Data.IORef (newIORef, readIORef,
17− writeIORef)
18import Network.Wai (Application, Request,
14import Network.Wai (Application, Request,
19− Response, ResponseReceived,
15+ Response, ResponseReceived)
20− requestBody,
21− strictRequestBody)
22import Servant.Server.Internal.ServantErr
16import Servant.Server.Internal.ServantErr
23
17
24type RoutingApplication =
18type RoutingApplication =
servant-server/test/Servant/Server/ErrorSpec.hs+4−4
@@ -42,7 +42,7 @@ errorOrderServer = \_ _ -> throwE err402
42
42
43errorOrderSpec :: Spec
43errorOrderSpec :: Spec
44errorOrderSpec = describe "HTTP error order"
44errorOrderSpec = describe "HTTP error order"
45− $ with (return $ serve errorOrderApi EmptyConfig errorOrderServer) $ do
45+ $ with (return $ serve errorOrderApi errorOrderServer) $ do
46 let badContentType = (hContentType, "text/plain")
46 let badContentType = (hContentType, "text/plain")
47 badAccept = (hAccept, "text/plain")
47 badAccept = (hAccept, "text/plain")
48 badMethod = methodGet
48 badMethod = methodGet
@@ -89,7 +89,7 @@ prioErrorsApi = Proxy
89prioErrorsSpec :: Spec
89prioErrorsSpec :: Spec
90prioErrorsSpec = describe "PrioErrors" $ do
90prioErrorsSpec = describe "PrioErrors" $ do
91 let server = return
91 let server = return
92− with (return $ serve prioErrorsApi EmptyConfig server) $ do
92+ with (return $ serve prioErrorsApi server) $ do
93 let check (mdescr, method) path (cdescr, ctype, body) resp =
93 let check (mdescr, method) path (cdescr, ctype, body) resp =
94 it fulldescr $
94 it fulldescr $
95 Test.Hspec.Wai.request method path [(hContentType, ctype)] body
95 Test.Hspec.Wai.request method path [(hContentType, ctype)] body
@@ -154,7 +154,7 @@ errorRetryServer
154
154
155errorRetrySpec :: Spec
155errorRetrySpec :: Spec
156errorRetrySpec = describe "Handler search"
156errorRetrySpec = describe "Handler search"
157− $ with (return $ serve errorRetryApi EmptyConfig errorRetryServer) $ do
157+ $ with (return $ serve errorRetryApi errorRetryServer) $ do
158
158
159 let jsonCT = (hContentType, "application/json")
159 let jsonCT = (hContentType, "application/json")
160 jsonAccept = (hAccept, "application/json")
160 jsonAccept = (hAccept, "application/json")
@@ -198,7 +198,7 @@ errorChoiceServer = return 0
198
198
199errorChoiceSpec :: Spec
199errorChoiceSpec :: Spec
200errorChoiceSpec = describe "Multiple handlers return errors"
200errorChoiceSpec = describe "Multiple handlers return errors"
201− $ with (return $ serve errorChoiceApi EmptyConfig errorChoiceServer) $ do
201+ $ with (return $ serve errorChoiceApi errorChoiceServer) $ do
202
202
203 it "should respond with 404 if no path matches" $ do
203 it "should respond with 404 if no path matches" $ do
204 request methodGet "" [] "" `shouldRespondWith` 404
204 request methodGet "" [] "" `shouldRespondWith` 404
servant-server/test/Servant/Server/Internal/EnterSpec.hs+2−2
@@ -48,12 +48,12 @@ combinedReaderServer = enter fReader combinedReaderServer'
48
48
49enterSpec :: Spec
49enterSpec :: Spec
50enterSpec = describe "Enter" $ do
50enterSpec = describe "Enter" $ do
51− with (return (serve readerAPI EmptyConfig readerServer)) $ do
51+ with (return (serve readerAPI readerServer)) $ do
52
52
53 it "allows running arbitrary monads" $ do
53 it "allows running arbitrary monads" $ do
54 get "int" `shouldRespondWith` "1797"
54 get "int" `shouldRespondWith` "1797"
55 post "string" "3" `shouldRespondWith` "\"hi\""{ matchStatus = 200 }
55 post "string" "3" `shouldRespondWith` "\"hi\""{ matchStatus = 200 }
56
56
57− with (return (serve combinedAPI EmptyConfig combinedReaderServer)) $ do
57+ with (return (serve combinedAPI combinedReaderServer)) $ do
58 it "allows combnation of enters" $ do
58 it "allows combnation of enters" $ do
59 get "bool" `shouldRespondWith` "true"
59 get "bool" `shouldRespondWith` "true"
servant-server/test/Servant/Server/UsingConfigSpec.hs+5−5
@@ -30,7 +30,7 @@ testServer s = return s
30
30
31oneEntryApp :: Application
31oneEntryApp :: Application
32oneEntryApp =
32oneEntryApp =
33− serve (Proxy :: Proxy OneEntryAPI) config testServer
33+ serveWithConfig (Proxy :: Proxy OneEntryAPI) config testServer
34 where
34 where
35 config :: Config '[String]
35 config :: Config '[String]
36 config = "configEntry" :. EmptyConfig
36 config = "configEntry" :. EmptyConfig
@@ -40,7 +40,7 @@ type OneEntryTwiceAPI =
40 "bar" :> ExtractFromConfig :> Get '[JSON] String
40 "bar" :> ExtractFromConfig :> Get '[JSON] String
41
41
42oneEntryTwiceApp :: Application
42oneEntryTwiceApp :: Application
43−oneEntryTwiceApp = serve (Proxy :: Proxy OneEntryTwiceAPI) config $
43+oneEntryTwiceApp = serveWithConfig (Proxy :: Proxy OneEntryTwiceAPI) config $
44 testServer :<|>
44 testServer :<|>
45 testServer
45 testServer
46 where
46 where
@@ -68,7 +68,7 @@ type InjectAPI =
68 Get '[JSON] String
68 Get '[JSON] String
69
69
70injectApp :: Application
70injectApp :: Application
71−injectApp = serve (Proxy :: Proxy InjectAPI) config $
71+injectApp = serveWithConfig (Proxy :: Proxy InjectAPI) config $
72 (\ s -> return s) :<|>
72 (\ s -> return s) :<|>
73 (\ s -> return ("tagged: " ++ s))
73 (\ s -> return ("tagged: " ++ s))
74 where
74 where
@@ -90,7 +90,7 @@ type WithBirdfaceAPI =
90 "bar" :> ExtractFromConfig :> Get '[JSON] String
90 "bar" :> ExtractFromConfig :> Get '[JSON] String
91
91
92withBirdfaceApp :: Application
92withBirdfaceApp :: Application
93−withBirdfaceApp = serve (Proxy :: Proxy WithBirdfaceAPI) config $
93+withBirdfaceApp = serveWithConfig (Proxy :: Proxy WithBirdfaceAPI) config $
94 testServer :<|>
94 testServer :<|>
95 testServer
95 testServer
96 where
96 where
@@ -112,7 +112,7 @@ type NamedConfigAPI =
112 ExtractFromConfig :> Get '[JSON] String)
112 ExtractFromConfig :> Get '[JSON] String)
113
113
114namedConfigApp :: Application
114namedConfigApp :: Application
115−namedConfigApp = serve (Proxy :: Proxy NamedConfigAPI) config return
115+namedConfigApp = serveWithConfig (Proxy :: Proxy NamedConfigAPI) config return
116 where
116 where
117 config :: Config '[NamedConfig "sub" '[String]]
117 config :: Config '[NamedConfig "sub" '[String]]
118 config = NamedConfig ("descend" :. EmptyConfig) :. EmptyConfig
118 config = NamedConfig ("descend" :. EmptyConfig) :. EmptyConfig
servant-server/test/Servant/ServerSpec.hs+15−16
@@ -49,7 +49,7 @@ import Servant.API ((:<|>) (..), (:>), Capture, Delete,
49 StdMethod (..), Verb, addHeader)
49 StdMethod (..), Verb, addHeader)
50import Servant.API.Internal.Test.ComprehensiveAPI
50import Servant.API.Internal.Test.ComprehensiveAPI
51import Servant.Server (ServantErr (..), Server, err404,
51import Servant.Server (ServantErr (..), Server, err404,
52− serve, Config(EmptyConfig))
52+ serve, serveWithConfig, Config(EmptyConfig))
53import Test.Hspec (Spec, context, describe, it,
53import Test.Hspec (Spec, context, describe, it,
54 shouldBe, shouldContain)
54 shouldBe, shouldContain)
55import Test.Hspec.Wai (get, liftIO, matchHeaders,
55import Test.Hspec.Wai (get, liftIO, matchHeaders,
@@ -67,7 +67,7 @@ import Servant.Server.Internal.Config
67-- * comprehensive api test
67-- * comprehensive api test
68
68
69-- This declaration simply checks that all instances are in place.
69-- This declaration simply checks that all instances are in place.
70−_ = serve comprehensiveAPI comprehensiveApiConfig
70+_ = serveWithConfig comprehensiveAPI comprehensiveApiConfig
71
71
72comprehensiveApiConfig :: Config '[NamedConfig "foo" '[]]
72comprehensiveApiConfig :: Config '[NamedConfig "foo" '[]]
73comprehensiveApiConfig = NamedConfig EmptyConfig :. EmptyConfig
73comprehensiveApiConfig = NamedConfig EmptyConfig :. EmptyConfig
@@ -112,7 +112,7 @@ verbSpec = describe "Servant.API.Verb" $ do
112 wrongMethod m = if m == methodPatch then methodPost else methodPatch
112 wrongMethod m = if m == methodPatch then methodPost else methodPatch
113 test desc api method (status :: Int) = context desc $
113 test desc api method (status :: Int) = context desc $
114
114
115− with (return $ serve api EmptyConfig server) $ do
115+ with (return $ serve api server) $ do
116
116
117 -- HEAD and 214/215 need not return bodies
117 -- HEAD and 214/215 need not return bodies
118 unless (status `elem` [214, 215] || method == methodHead) $
118 unless (status `elem` [214, 215] || method == methodHead) $
@@ -187,7 +187,7 @@ captureServer legs = case legs of
187captureSpec :: Spec
187captureSpec :: Spec
188captureSpec = do
188captureSpec = do
189 describe "Servant.API.Capture" $ do
189 describe "Servant.API.Capture" $ do
190− with (return (serve captureApi EmptyConfig captureServer)) $ do
190+ with (return (serve captureApi captureServer)) $ do
191
191
192 it "can capture parts of the 'pathInfo'" $ do
192 it "can capture parts of the 'pathInfo'" $ do
193 response <- get "/2"
193 response <- get "/2"
@@ -198,7 +198,6 @@ captureSpec = do
198
198
199 with (return (serve
199 with (return (serve
200 (Proxy :: Proxy (Capture "captured" String :> Raw))
200 (Proxy :: Proxy (Capture "captured" String :> Raw))
201− EmptyConfig
202 (\ "captured" request_ respond ->
201 (\ "captured" request_ respond ->
203 respond $ responseLBS ok200 [] (cs $ show $ pathInfo request_)))) $ do
202 respond $ responseLBS ok200 [] (cs $ show $ pathInfo request_)))) $ do
204 it "strips the captured path snippet from pathInfo" $ do
203 it "strips the captured path snippet from pathInfo" $ do
@@ -232,7 +231,7 @@ queryParamSpec :: Spec
232queryParamSpec = do
231queryParamSpec = do
233 describe "Servant.API.QueryParam" $ do
232 describe "Servant.API.QueryParam" $ do
234 it "allows retrieving simple GET parameters" $
233 it "allows retrieving simple GET parameters" $
235− (flip runSession) (serve queryParamApi EmptyConfig qpServer) $ do
234+ (flip runSession) (serve queryParamApi qpServer) $ do
236 let params1 = "?name=bob"
235 let params1 = "?name=bob"
237 response1 <- Network.Wai.Test.request defaultRequest{
236 response1 <- Network.Wai.Test.request defaultRequest{
238 rawQueryString = params1,
237 rawQueryString = params1,
@@ -244,7 +243,7 @@ queryParamSpec = do
244 }
243 }
245
244
246 it "allows retrieving lists in GET parameters" $
245 it "allows retrieving lists in GET parameters" $
247− (flip runSession) (serve queryParamApi EmptyConfig qpServer) $ do
246+ (flip runSession) (serve queryParamApi qpServer) $ do
248 let params2 = "?names[]=bob&names[]=john"
247 let params2 = "?names[]=bob&names[]=john"
249 response2 <- Network.Wai.Test.request defaultRequest{
248 response2 <- Network.Wai.Test.request defaultRequest{
250 rawQueryString = params2,
249 rawQueryString = params2,
@@ -258,7 +257,7 @@ queryParamSpec = do
258
257
259
258
260 it "allows retrieving value-less GET parameters" $
259 it "allows retrieving value-less GET parameters" $
261− (flip runSession) (serve queryParamApi EmptyConfig qpServer) $ do
260+ (flip runSession) (serve queryParamApi qpServer) $ do
262 let params3 = "?capitalize"
261 let params3 = "?capitalize"
263 response3 <- Network.Wai.Test.request defaultRequest{
262 response3 <- Network.Wai.Test.request defaultRequest{
264 rawQueryString = params3,
263 rawQueryString = params3,
@@ -310,7 +309,7 @@ reqBodySpec = describe "Servant.API.ReqBody" $ do
310 mkReq method x = Test.Hspec.Wai.request method x
309 mkReq method x = Test.Hspec.Wai.request method x
311 [(hContentType, "application/json;charset=utf-8")]
310 [(hContentType, "application/json;charset=utf-8")]
312
311
313− with (return $ serve reqBodyApi EmptyConfig server) $ do
312+ with (return $ serve reqBodyApi server) $ do
314
313
315 it "passes the argument to the handler" $ do
314 it "passes the argument to the handler" $ do
316 response <- mkReq methodPost "" (encode alice)
315 response <- mkReq methodPost "" (encode alice)
@@ -343,13 +342,13 @@ headerSpec = describe "Servant.API.Header" $ do
343 expectsString (Just x) = when (x /= "more from you") $ error "Expected more from you"
342 expectsString (Just x) = when (x /= "more from you") $ error "Expected more from you"
344 expectsString Nothing = error "Expected a string"
343 expectsString Nothing = error "Expected a string"
345
344
346− with (return (serve headerApi EmptyConfig expectsInt)) $ do
345+ with (return (serve headerApi expectsInt)) $ do
347 let delete' x = Test.Hspec.Wai.request methodDelete x [("MyHeader", "5")]
346 let delete' x = Test.Hspec.Wai.request methodDelete x [("MyHeader", "5")]
348
347
349 it "passes the header to the handler (Int)" $
348 it "passes the header to the handler (Int)" $
350 delete' "/" "" `shouldRespondWith` 200
349 delete' "/" "" `shouldRespondWith` 200
351
350
352− with (return (serve headerApi EmptyConfig expectsString)) $ do
351+ with (return (serve headerApi expectsString)) $ do
353 let delete' x = Test.Hspec.Wai.request methodDelete x [("MyHeader", "more from you")]
352 let delete' x = Test.Hspec.Wai.request methodDelete x [("MyHeader", "more from you")]
354
353
355 it "passes the header to the handler (String)" $
354 it "passes the header to the handler (String)" $
@@ -373,7 +372,7 @@ rawSpec :: Spec
373rawSpec = do
372rawSpec = do
374 describe "Servant.API.Raw" $ do
373 describe "Servant.API.Raw" $ do
375 it "runs applications" $ do
374 it "runs applications" $ do
376− (flip runSession) (serve rawApi EmptyConfig (rawApplication (const (42 :: Integer)))) $ do
375+ (flip runSession) (serve rawApi (rawApplication (const (42 :: Integer)))) $ do
377 response <- Network.Wai.Test.request defaultRequest{
376 response <- Network.Wai.Test.request defaultRequest{
378 pathInfo = ["foo"]
377 pathInfo = ["foo"]
379 }
378 }
@@ -381,7 +380,7 @@ rawSpec = do
381 simpleBody response `shouldBe` "42"
380 simpleBody response `shouldBe` "42"
382
381
383 it "gets the pathInfo modified" $ do
382 it "gets the pathInfo modified" $ do
384− (flip runSession) (serve rawApi EmptyConfig (rawApplication pathInfo)) $ do
383+ (flip runSession) (serve rawApi (rawApplication pathInfo)) $ do
385 response <- Network.Wai.Test.request defaultRequest{
384 response <- Network.Wai.Test.request defaultRequest{
386 pathInfo = ["foo", "bar"]
385 pathInfo = ["foo", "bar"]
387 }
386 }
@@ -415,7 +414,7 @@ alternativeServer =
415alternativeSpec :: Spec
414alternativeSpec :: Spec
416alternativeSpec = do
415alternativeSpec = do
417 describe "Servant.API.Alternative" $ do
416 describe "Servant.API.Alternative" $ do
418− with (return $ serve alternativeApi EmptyConfig alternativeServer) $ do
417+ with (return $ serve alternativeApi alternativeServer) $ do
419
418
420 it "unions endpoints" $ do
419 it "unions endpoints" $ do
421 response <- get "/foo"
420 response <- get "/foo"
@@ -450,7 +449,7 @@ responseHeadersServer = let h = return $ addHeader 5 $ addHeader "kilroy" "hi"
450
449
451responseHeadersSpec :: Spec
450responseHeadersSpec :: Spec
452responseHeadersSpec = describe "ResponseHeaders" $ do
451responseHeadersSpec = describe "ResponseHeaders" $ do
453− with (return $ serve (Proxy :: Proxy ResponseHeadersApi) EmptyConfig responseHeadersServer) $ do
452+ with (return $ serve (Proxy :: Proxy ResponseHeadersApi) responseHeadersServer) $ do
454
453
455 let methods = [methodGet, methodPost, methodPut, methodPatch]
454 let methods = [methodGet, methodPost, methodPut, methodPatch]
456
455
@@ -516,7 +515,7 @@ miscServ = versionHandler
516 hostHandler = return . show
515 hostHandler = return . show
517
516
518miscCombinatorSpec :: Spec
517miscCombinatorSpec :: Spec
519−miscCombinatorSpec = with (return $ serve miscApi EmptyConfig miscServ) $
518+miscCombinatorSpec = with (return $ serve miscApi miscServ) $
520 describe "Misc. combinators for request inspection" $ do
519 describe "Misc. combinators for request inspection" $ do
521 it "Successfully gets the HTTP version specified in the request" $
520 it "Successfully gets the HTTP version specified in the request" $
522 go "/version" "\"HTTP/1.0\""
521 go "/version" "\"HTTP/1.0\""
servant-server/test/Servant/Utils/StaticFilesSpec.hs+2−2
@@ -16,7 +16,7 @@ import Test.Hspec (Spec, around_, describe, it)
16import Test.Hspec.Wai (get, shouldRespondWith, with)
16import Test.Hspec.Wai (get, shouldRespondWith, with)
17
17
18import Servant.API ((:<|>) ((:<|>)), Capture, Get, Raw, (:>), JSON)
18import Servant.API ((:<|>) ((:<|>)), Capture, Get, Raw, (:>), JSON)
19−import Servant.Server (Server, serve, Config(EmptyConfig))
19+import Servant.Server (Server, serve)
20import Servant.ServerSpec (Person (Person))
20import Servant.ServerSpec (Person (Person))
21import Servant.Utils.StaticFiles (serveDirectory)
21import Servant.Utils.StaticFiles (serveDirectory)
22
22
@@ -29,7 +29,7 @@ api :: Proxy Api
29api = Proxy
29api = Proxy
30
30
31app :: Application
31app :: Application
32−app = serve api EmptyConfig server
32+app = serve api server
33
33
34server :: Server Api
34server :: Server Api
35server =
35server =