diff --git a/servant-examples/getting-started/getting-started.hs b/servant-examples/getting-started/getting-started.hs deleted file mode 100644 index b1335af7..00000000 --- a/servant-examples/getting-started/getting-started.hs +++ /dev/null @@ -1,39 +0,0 @@ -import Network.Wai -import Network.Wai.Handler.Warp -import System.Environment - -import qualified GS1 -import qualified GS2 -import qualified GS3 -import qualified GS4 -import qualified GS5 -import qualified GS6 -import qualified GS7 -import qualified GS9 -import qualified GS10 - -app :: String -> (Application -> IO ()) -> IO () -app n f = case n of - "1" -> f GS1.app - "2" -> f GS2.app - "3" -> f GS3.app - "4" -> f GS4.app - "5" -> f GS5.app - "6" -> f GS6.app - "7" -> f GS7.app - "8" -> f GS3.app - "9" -> GS9.writeJSFiles >> f GS9.app - "10" -> f GS10.app - _ -> usage - -main :: IO () -main = do - args <- getArgs - case args of - [n] -> app n (run 8081) - _ -> usage - -usage :: IO () -usage = do - putStrLn "Usage:\t getting-started N" - putStrLn "\t\twhere N is the number of the example you want to run." diff --git a/servant-examples/servant-examples.cabal b/servant-examples/servant-examples.cabal index 30db3497..371a4fd3 100644 --- a/servant-examples/servant-examples.cabal +++ b/servant-examples/servant-examples.cabal @@ -13,9 +13,9 @@ category: Web build-type: Simple cabal-version: >=1.10 -executable getting-started - main-is: getting-started.hs - other-modules: GS1, GS2, GS3, GS4, GS5, GS6, GS7, GS8, GS9, GS10 +executable tutorial + main-is: tutorial.hs + other-modules: T1, T2, T3, T4, T5, T6, T7, T8, T9, T10 build-depends: aeson >= 0.8 , base >= 4.7 @@ -36,12 +36,12 @@ executable getting-started , transformers , wai , warp - hs-source-dirs: getting-started + hs-source-dirs: tutorial default-language: Haskell2010 -executable gs8-main - main-is: gs8-main.hs - hs-source-dirs: getting-started +executable t8-main + main-is: t8-main.hs + hs-source-dirs: tutorial default-language: Haskell2010 build-depends: aeson diff --git a/servant-examples/getting-started/GS1.hs b/servant-examples/tutorial/T1.hs similarity index 98% rename from servant-examples/getting-started/GS1.hs rename to servant-examples/tutorial/T1.hs index a6daffec..9fb93c8c 100644 --- a/servant-examples/getting-started/GS1.hs +++ b/servant-examples/tutorial/T1.hs @@ -2,7 +2,7 @@ {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE TypeOperators #-} -module GS1 where +module T1 where import Data.Aeson import Data.Time.Calendar diff --git a/servant-examples/getting-started/GS10.hs b/servant-examples/tutorial/T10.hs similarity index 64% rename from servant-examples/getting-started/GS10.hs rename to servant-examples/tutorial/T10.hs index fb8e4bf3..39e48e04 100644 --- a/servant-examples/getting-started/GS10.hs +++ b/servant-examples/tutorial/T10.hs @@ -4,7 +4,7 @@ {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE MultiParamTypeClasses #-} -module GS10 where +module T10 where import Data.ByteString.Lazy (ByteString) import Data.Text.Lazy (pack) @@ -13,9 +13,9 @@ import Network.HTTP.Types import Network.Wai import Servant import Servant.Docs -import qualified GS3 +import qualified T3 -type DocsAPI = GS3.API :<|> Raw +type DocsAPI = T3.API :<|> Raw instance ToCapture (Capture "x" Int) where toCapture _ = DocCapture "x" "(integer) position on the x axis" @@ -23,8 +23,8 @@ instance ToCapture (Capture "x" Int) where instance ToCapture (Capture "y" Int) where toCapture _ = DocCapture "y" "(integer) position on the y axis" -instance ToSample GS3.Position GS3.Position where - toSample _ = Just (GS3.Position 3 14) +instance ToSample T3.Position T3.Position where + toSample _ = Just (T3.Position 3 14) instance ToParam (QueryParam "name" String) where toParam _ = @@ -33,20 +33,20 @@ instance ToParam (QueryParam "name" String) where "Name of the person to say hello to." Normal -instance ToSample GS3.HelloMessage GS3.HelloMessage where +instance ToSample T3.HelloMessage T3.HelloMessage where toSamples _ = - [ ("When a value is provided for 'name'", GS3.HelloMessage "Hello, Alp") - , ("When 'name' is not specified", GS3.HelloMessage "Hello, anonymous coward") + [ ("When a value is provided for 'name'", T3.HelloMessage "Hello, Alp") + , ("When 'name' is not specified", T3.HelloMessage "Hello, anonymous coward") ] -ci :: GS3.ClientInfo -ci = GS3.ClientInfo "Alp" "alp@foo.com" 26 ["haskell", "mathematics"] +ci :: T3.ClientInfo +ci = T3.ClientInfo "Alp" "alp@foo.com" 26 ["haskell", "mathematics"] -instance ToSample GS3.ClientInfo GS3.ClientInfo where +instance ToSample T3.ClientInfo T3.ClientInfo where toSample _ = Just ci -instance ToSample GS3.Email GS3.Email where - toSample _ = Just (GS3.emailForClient ci) +instance ToSample T3.Email T3.Email where + toSample _ = Just (T3.emailForClient ci) api :: Proxy DocsAPI api = Proxy @@ -55,12 +55,12 @@ docsBS :: ByteString docsBS = encodeUtf8 . pack . markdown - $ docsWithIntros [intro] GS3.api + $ docsWithIntros [intro] T3.api where intro = DocIntro "Welcome" ["This is our super webservice's API.", "Enjoy!"] server :: Server DocsAPI -server = GS3.server :<|> serveDocs +server = T3.server :<|> serveDocs where serveDocs _ respond = respond $ responseLBS ok200 [plain] docsBS diff --git a/servant-examples/getting-started/GS2.hs b/servant-examples/tutorial/T2.hs similarity index 98% rename from servant-examples/getting-started/GS2.hs rename to servant-examples/tutorial/T2.hs index bf935320..69ded18c 100644 --- a/servant-examples/getting-started/GS2.hs +++ b/servant-examples/tutorial/T2.hs @@ -2,7 +2,7 @@ {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE TypeOperators #-} -module GS2 where +module T2 where import Data.Aeson import Data.Time.Calendar diff --git a/servant-examples/getting-started/GS3.hs b/servant-examples/tutorial/T3.hs similarity index 99% rename from servant-examples/getting-started/GS3.hs rename to servant-examples/tutorial/T3.hs index 505982cf..dcff930b 100644 --- a/servant-examples/getting-started/GS3.hs +++ b/servant-examples/tutorial/T3.hs @@ -2,7 +2,7 @@ {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE TypeOperators #-} -module GS3 where +module T3 where import Control.Monad.Trans.Either import Data.Aeson diff --git a/servant-examples/getting-started/GS4.hs b/servant-examples/tutorial/T4.hs similarity index 98% rename from servant-examples/getting-started/GS4.hs rename to servant-examples/tutorial/T4.hs index 89e7cce3..595eabcb 100644 --- a/servant-examples/getting-started/GS4.hs +++ b/servant-examples/tutorial/T4.hs @@ -4,7 +4,7 @@ {-# LANGUAGE TypeOperators #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE OverloadedStrings #-} -module GS4 where +module T4 where import Data.Aeson import Data.Foldable (foldMap) diff --git a/servant-examples/getting-started/GS5.hs b/servant-examples/tutorial/T5.hs similarity index 98% rename from servant-examples/getting-started/GS5.hs rename to servant-examples/tutorial/T5.hs index 6a6c91b7..0811fd9b 100644 --- a/servant-examples/getting-started/GS5.hs +++ b/servant-examples/tutorial/T5.hs @@ -3,7 +3,7 @@ {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE TypeOperators #-} {-# LANGUAGE OverloadedStrings #-} -module GS5 where +module T5 where import Control.Monad.IO.Class import Control.Monad.Trans.Either diff --git a/servant-examples/getting-started/GS6.hs b/servant-examples/tutorial/T6.hs similarity index 80% rename from servant-examples/getting-started/GS6.hs rename to servant-examples/tutorial/T6.hs index 4fdc3faa..c0abb1df 100644 --- a/servant-examples/getting-started/GS6.hs +++ b/servant-examples/tutorial/T6.hs @@ -1,7 +1,7 @@ {-# LANGUAGE DataKinds #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TypeOperators #-} -module GS6 where +module T6 where import Network.Wai import Servant @@ -12,7 +12,7 @@ api :: Proxy API api = Proxy server :: Server API -server = serveDirectory "getting-started" +server = serveDirectory "tutorial" app :: Application app = serve api server diff --git a/servant-examples/getting-started/GS7.hs b/servant-examples/tutorial/T7.hs similarity index 97% rename from servant-examples/getting-started/GS7.hs rename to servant-examples/tutorial/T7.hs index 83dfb93a..d67cfcd4 100644 --- a/servant-examples/getting-started/GS7.hs +++ b/servant-examples/tutorial/T7.hs @@ -1,7 +1,7 @@ {-# LANGUAGE DataKinds #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TypeOperators #-} -module GS7 where +module T7 where import Control.Monad.Trans.Either import Control.Monad.Trans.Reader diff --git a/servant-examples/getting-started/GS8.hs b/servant-examples/tutorial/T8.hs similarity index 97% rename from servant-examples/getting-started/GS8.hs rename to servant-examples/tutorial/T8.hs index ace1991a..089702bc 100644 --- a/servant-examples/getting-started/GS8.hs +++ b/servant-examples/tutorial/T8.hs @@ -1,14 +1,14 @@ {-# LANGUAGE DataKinds #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TypeOperators #-} -module GS8 where +module T8 where import Control.Monad.Trans.Either import Data.Aeson import Servant import Servant.Client -import GS3 +import T3 position :: Int -- ^ value for "x" -> Int -- ^ value for "y" diff --git a/servant-examples/getting-started/GS9.hs b/servant-examples/tutorial/T9.hs similarity index 94% rename from servant-examples/getting-started/GS9.hs rename to servant-examples/tutorial/T9.hs index 382dd068..1b0633f0 100644 --- a/servant-examples/getting-started/GS9.hs +++ b/servant-examples/tutorial/T9.hs @@ -3,7 +3,7 @@ {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE TypeOperators #-} {-# LANGUAGE OverloadedStrings #-} -module GS9 where +module T9 where import Control.Applicative import Control.Monad.IO.Class @@ -89,16 +89,16 @@ server = randomPoint server' :: Server API' server' = server - :<|> serveDirectory "getting-started/gs9" + :<|> serveDirectory "tutorial/t9" apiJS :: String apiJS = jsForAPI api writeJSFiles :: IO () writeJSFiles = do - writeFile "getting-started/gs9/api.js" apiJS + writeFile "tutorial/t9/api.js" apiJS jq <- readFile =<< JQ.file - writeFile "getting-started/gs9/jq.js" jq + writeFile "tutorial/t9/jq.js" jq app :: Application app = serve api' server' diff --git a/servant-examples/getting-started/gs8-main.hs b/servant-examples/tutorial/t8-main.hs similarity index 70% rename from servant-examples/getting-started/gs8-main.hs rename to servant-examples/tutorial/t8-main.hs index b6a9e30e..b70d5a61 100644 --- a/servant-examples/getting-started/gs8-main.hs +++ b/servant-examples/tutorial/t8-main.hs @@ -1,4 +1,4 @@ -import GS8 +import T8 main :: IO () main = run diff --git a/servant-examples/getting-started/gs9/index.html b/servant-examples/tutorial/t9/index.html similarity index 93% rename from servant-examples/getting-started/gs9/index.html rename to servant-examples/tutorial/t9/index.html index 27d8630c..7ec49c70 100644 --- a/servant-examples/getting-started/gs9/index.html +++ b/servant-examples/tutorial/t9/index.html @@ -3,7 +3,7 @@
-