diff --git a/src/Servant/Server.hs b/src/Servant/Server.hs index d8661585..3d8156ae 100644 --- a/src/Servant/Server.hs +++ b/src/Servant/Server.hs @@ -11,10 +11,12 @@ module Servant.Server HasServer(..) ) where -import Data.Proxy -import Network.Wai +import Data.Proxy (Proxy) +import Network.Wai (Application) + import Servant.Server.Internal + -- * Implementing Servers -- | 'serve' allows you to implement an API and produce a wai 'Application'. @@ -30,7 +32,7 @@ import Servant.Server.Internal -- > postBook book = ... -- > -- > myApi :: Proxy MyApi --- > myApi = Proxy +-- > myApi = Proxy -- > -- > app :: Application -- > app = serve myApi server @@ -39,4 +41,3 @@ import Servant.Server.Internal -- > main = Network.Wai.Handler.Warp.run 8080 app serve :: HasServer layout => Proxy layout -> Server layout -> Application serve p server = toApplication (route p server) - diff --git a/src/Servant/Server/Internal.hs b/src/Servant/Server/Internal.hs index 0421124b..02d81bf9 100644 --- a/src/Servant/Server/Internal.hs +++ b/src/Servant/Server/Internal.hs @@ -7,24 +7,26 @@ {-# LANGUAGE ScopedTypeVariables #-} module Servant.Server.Internal where -import Control.Applicative -import Control.Monad.Trans.Either -import Data.Aeson +import Control.Applicative ((<$>)) +import Control.Monad.Trans.Either (EitherT, runEitherT) +import Data.Aeson (ToJSON, FromJSON, encode, decode') import qualified Data.ByteString as B import qualified Data.ByteString.Lazy as BL -import Data.IORef +import Data.IORef (newIORef, readIORef, writeIORef) import Data.Maybe (catMaybes) -import Data.Monoid -import Data.Proxy -import Data.String -import Data.String.Conversions +import Data.Monoid (Monoid, mempty, mappend) +import Data.Proxy (Proxy(Proxy)) +import Data.String (fromString) +import Data.String.Conversions (cs, (<>)) import Data.Text.Encoding (decodeUtf8) import Data.Text (Text) -import GHC.TypeLits +import GHC.TypeLits (KnownSymbol, symbolVal) import Network.HTTP.Types hiding (Header) -import Network.Wai -import Servant.API -import Servant.Common.Text +import Network.Wai (Response, Request, ResponseReceived, Application, pathInfo, requestBody, + strictRequestBody, lazyRequestBody, requestHeaders, requestMethod, + rawQueryString, responseLBS) +import Servant.API (QueryParams, QueryParam, QueryFlag, ReqBody, Header, Capture, Get, Delete, Put, Post, Raw, (:>), (:<|>)(..)) +import Servant.Common.Text (FromText, fromText) data ReqBodyState = Uncalled | Called !B.ByteString diff --git a/src/Servant/Utils/StaticFiles.hs b/src/Servant/Utils/StaticFiles.hs index 17146aa7..9cd5fdcc 100644 --- a/src/Servant/Utils/StaticFiles.hs +++ b/src/Servant/Utils/StaticFiles.hs @@ -7,9 +7,9 @@ module Servant.Utils.StaticFiles ( ) where import Filesystem.Path.CurrentOS (decodeString) -import Network.Wai.Application.Static -import Servant.API.Raw -import Servant.Server.Internal +import Network.Wai.Application.Static (staticApp, defaultFileServerSettings) +import Servant.API.Raw (Raw) +import Servant.Server.Internal (Server) -- | Serve anything under the specified directory as a 'Raw' endpoint. -- diff --git a/test/Servant/ServerSpec.hs b/test/Servant/ServerSpec.hs index 7ae69c17..c907cd26 100644 --- a/test/Servant/ServerSpec.hs +++ b/test/Servant/ServerSpec.hs @@ -8,28 +8,28 @@ module Servant.ServerSpec where -import Control.Monad.Trans.Either -import Data.Aeson -import Data.Char -import Data.Proxy -import Data.String -import Data.String.Conversions -import GHC.Generics -import Network.HTTP.Types -import Network.Wai -import Network.Wai.Test -import Test.Hspec -import Test.Hspec.Wai +import Control.Monad.Trans.Either (EitherT, left) +import Data.Aeson (ToJSON, FromJSON, encode, decode') +import Data.Char (toUpper) +import Data.Proxy (Proxy(Proxy)) +import Data.String (fromString) +import Data.String.Conversions (cs) +import GHC.Generics (Generic) +import Network.HTTP.Types (parseQuery, ok200) +import Network.Wai (Application, Request, responseLBS, pathInfo, queryString, rawQueryString) +import Network.Wai.Test (runSession, request, defaultRequest, simpleBody) +import Test.Hspec (Spec, describe, it, shouldBe) +import Test.Hspec.Wai (liftIO, with, get, post, shouldRespondWith, matchStatus) -import Servant.API.Capture -import Servant.API.Get -import Servant.API.ReqBody -import Servant.API.Post -import Servant.API.QueryParam -import Servant.API.Raw -import Servant.API.Sub -import Servant.API.Alternative -import Servant.Server +import Servant.API.Capture (Capture) +import Servant.API.Get (Get) +import Servant.API.ReqBody (ReqBody) +import Servant.API.Post (Post) +import Servant.API.QueryParam (QueryParam, QueryParams, QueryFlag) +import Servant.API.Raw (Raw) +import Servant.API.Sub ((:>)) +import Servant.API.Alternative ((:<|>)((:<|>))) +import Servant.Server (Server, serve) -- * test data types @@ -94,8 +94,8 @@ captureSpec = do with (return (serve (Proxy :: Proxy (Capture "captured" String :> Raw)) - (\ "captured" request respond -> - respond $ responseLBS ok200 [] (cs $ show $ pathInfo request)))) $ do + (\ "captured" request_ respond -> + respond $ responseLBS ok200 [] (cs $ show $ pathInfo request_)))) $ do it "strips the captured path snippet from pathInfo" $ do get "/captured/foo" `shouldRespondWith` (fromString (show ["foo" :: String])) @@ -134,7 +134,7 @@ qpServer = queryParamServer :<|> qpNames :<|> qpCapitalize qpCapitalize False = return alice qpCapitalize True = return alice { name = map toUpper (name alice) } - queryParamServer (Just name) = return alice{name = name} + queryParamServer (Just name_) = return alice{name = name_} queryParamServer Nothing = return alice queryParamSpec :: Spec @@ -222,7 +222,7 @@ type RawApi = "foo" :> Raw rawApi :: Proxy RawApi rawApi = Proxy rawApplication :: Show a => (Request -> a) -> Application -rawApplication f request respond = respond $ responseLBS ok200 [] (cs $ show $ f request) +rawApplication f request_ respond = respond $ responseLBS ok200 [] (cs $ show $ f request_) rawSpec :: Spec rawSpec = do @@ -264,7 +264,7 @@ unionSpec = do liftIO $ do decode' (simpleBody response) `shouldBe` Just alice - response <- get "/bar" + response_ <- get "/bar" liftIO $ do - decode' (simpleBody response) `shouldBe` + decode' (simpleBody response_) `shouldBe` Just jerry diff --git a/test/Servant/Utils/StaticFilesSpec.hs b/test/Servant/Utils/StaticFilesSpec.hs index 8d34f90f..de7b9e3c 100644 --- a/test/Servant/Utils/StaticFilesSpec.hs +++ b/test/Servant/Utils/StaticFilesSpec.hs @@ -5,22 +5,22 @@ {-# OPTIONS_GHC -fno-warn-orphans #-} module Servant.Utils.StaticFilesSpec where -import Control.Exception -import Data.Proxy -import Network.Wai -import System.Directory -import System.IO.Temp -import Test.Hspec hiding (pending) -import Test.Hspec.Wai +import Control.Exception (bracket) +import Data.Proxy (Proxy(Proxy)) +import Network.Wai (Application) +import System.Directory (getCurrentDirectory, setCurrentDirectory, createDirectory) +import System.IO.Temp (withSystemTempDirectory) +import Test.Hspec (Spec, describe, it, around_) +import Test.Hspec.Wai (with, get, shouldRespondWith) -import Servant.API.Alternative -import Servant.API.Capture -import Servant.API.Get -import Servant.API.Raw -import Servant.API.Sub -import Servant.Server -import Servant.ServerSpec -import Servant.Utils.StaticFiles +import Servant.API.Alternative ((:<|>)((:<|>))) +import Servant.API.Capture (Capture) +import Servant.API.Get (Get) +import Servant.API.Raw (Raw) +import Servant.API.Sub ((:>)) +import Servant.Server (Server, serve) +import Servant.ServerSpec (Person(Person)) +import Servant.Utils.StaticFiles (serveDirectory) type Api = "dummy_api" :> Capture "person_name" String :> Get Person @@ -35,7 +35,7 @@ app = serve api server server :: Server Api server = - (\ name -> return (Person name 42)) + (\ name_ -> return (Person name_ 42)) :<|> serveDirectory "static" withStaticFiles :: IO () -> IO ()