on master help sign in
getting-started -> tutorial
commit39d114ab1227c63ddcd2b2ad31ac9cef56981f9c authorAlp Mestanogullari <alpmestan@gmail.com> dateSun 10 May 2015, 13:39 (11 years ago) parent4653744
16 files changed+77−77
servant-examples/getting-started/getting-started.hs−39 servant-examples/servant-examples.cabal+7−7 servant-examples/getting-started/GS1.hs → servant-examples/tutorial/T1.hs+1−1 servant-examples/getting-started/GS10.hs → servant-examples/tutorial/T10.hs+15−15 servant-examples/getting-started/GS2.hs → servant-examples/tutorial/T2.hs+1−1 servant-examples/getting-started/GS3.hs → servant-examples/tutorial/T3.hs+1−1 servant-examples/getting-started/GS4.hs → servant-examples/tutorial/T4.hs+1−1 servant-examples/getting-started/GS5.hs → servant-examples/tutorial/T5.hs+1−1 servant-examples/getting-started/GS6.hs → servant-examples/tutorial/T6.hs+2−2 servant-examples/getting-started/GS7.hs → servant-examples/tutorial/T7.hs+1−1 servant-examples/getting-started/GS8.hs → servant-examples/tutorial/T8.hs+2−2 servant-examples/getting-started/GS9.hs → servant-examples/tutorial/T9.hs+4−4 servant-examples/getting-started/gs8-main.hs → servant-examples/tutorial/t8-main.hs+1−1 servant-examples/getting-started/gs9/index.html → servant-examples/tutorial/t9/index.html+1−1 servant-examples/getting-started/gs9/ui.js → servant-examples/tutorial/t9/ui.js servant-examples/tutorial/tutorial.hs+39
servant-examples/getting-started/getting-started.hsdeleted−39
@@ -1,39 +0,0 @@
1−import Network.Wai
2−import Network.Wai.Handler.Warp
3−import System.Environment
4−
5−import qualified GS1
6−import qualified GS2
7−import qualified GS3
8−import qualified GS4
9−import qualified GS5
10−import qualified GS6
11−import qualified GS7
12−import qualified GS9
13−import qualified GS10
14−
15−app :: String -> (Application -> IO ()) -> IO ()
16−app n f = case n of
17− "1" -> f GS1.app
18− "2" -> f GS2.app
19− "3" -> f GS3.app
20− "4" -> f GS4.app
21− "5" -> f GS5.app
22− "6" -> f GS6.app
23− "7" -> f GS7.app
24− "8" -> f GS3.app
25− "9" -> GS9.writeJSFiles >> f GS9.app
26− "10" -> f GS10.app
27− _ -> usage
28−
29−main :: IO ()
30−main = do
31− args <- getArgs
32− case args of
33− [n] -> app n (run 8081)
34− _ -> usage
35−
36−usage :: IO ()
37−usage = do
38− putStrLn "Usage:\t getting-started N"
39− putStrLn "\t\twhere N is the number of the example you want to run."
servant-examples/servant-examples.cabal+7−7
@@ -13,9 +13,9 @@ category: Web
1313build-type: Simple
1414cabal-version: >=1.10
1515
16−executable getting-started
17− main-is: getting-started.hs
18− other-modules: GS1, GS2, GS3, GS4, GS5, GS6, GS7, GS8, GS9, GS10
16+executable tutorial
17+ main-is: tutorial.hs
18+ other-modules: T1, T2, T3, T4, T5, T6, T7, T8, T9, T10
1919 build-depends:
2020 aeson >= 0.8
2121 , base >= 4.7
@@ -36,12 +36,12 @@ executable getting-started
3636 , transformers
3737 , wai
3838 , warp
39− hs-source-dirs: getting-started
39+ hs-source-dirs: tutorial
4040 default-language: Haskell2010
4141
42−executable gs8-main
43− main-is: gs8-main.hs
44− hs-source-dirs: getting-started
42+executable t8-main
43+ main-is: t8-main.hs
44+ hs-source-dirs: tutorial
4545 default-language: Haskell2010
4646 build-depends:
4747 aeson
servant-examples/getting-started/GS1.hs → servant-examples/tutorial/T1.hsrenamed+1−1
@@ -2,7 +2,7 @@
22{-# LANGUAGE TypeFamilies #-}
33{-# LANGUAGE DeriveGeneric #-}
44{-# LANGUAGE TypeOperators #-}
5−module GS1 where
5+module T1 where
66
77import Data.Aeson
88import Data.Time.Calendar
servant-examples/getting-started/GS10.hs → servant-examples/tutorial/T10.hsrenamed+15−15
@@ -4,7 +4,7 @@
44{-# LANGUAGE FlexibleInstances #-}
55{-# LANGUAGE OverloadedStrings #-}
66{-# LANGUAGE MultiParamTypeClasses #-}
7−module GS10 where
7+module T10 where
88
99import Data.ByteString.Lazy (ByteString)
1010import Data.Text.Lazy (pack)
@@ -13,9 +13,9 @@ import Network.HTTP.Types
1313import Network.Wai
1414import Servant
1515import Servant.Docs
16−import qualified GS3
16+import qualified T3
1717
18−type DocsAPI = GS3.API :<|> Raw
18+type DocsAPI = T3.API :<|> Raw
1919
2020instance ToCapture (Capture "x" Int) where
2121 toCapture _ = DocCapture "x" "(integer) position on the x axis"
@@ -23,8 +23,8 @@ instance ToCapture (Capture "x" Int) where
2323instance ToCapture (Capture "y" Int) where
2424 toCapture _ = DocCapture "y" "(integer) position on the y axis"
2525
26−instance ToSample GS3.Position GS3.Position where
27− toSample _ = Just (GS3.Position 3 14)
26+instance ToSample T3.Position T3.Position where
27+ toSample _ = Just (T3.Position 3 14)
2828
2929instance ToParam (QueryParam "name" String) where
3030 toParam _ =
@@ -33,20 +33,20 @@ instance ToParam (QueryParam "name" String) where
3333 "Name of the person to say hello to."
3434 Normal
3535
36−instance ToSample GS3.HelloMessage GS3.HelloMessage where
36+instance ToSample T3.HelloMessage T3.HelloMessage where
3737 toSamples _ =
38− [ ("When a value is provided for 'name'", GS3.HelloMessage "Hello, Alp")
39− , ("When 'name' is not specified", GS3.HelloMessage "Hello, anonymous coward")
38+ [ ("When a value is provided for 'name'", T3.HelloMessage "Hello, Alp")
39+ , ("When 'name' is not specified", T3.HelloMessage "Hello, anonymous coward")
4040 ]
4141
42−ci :: GS3.ClientInfo
43−ci = GS3.ClientInfo "Alp" "alp@foo.com" 26 ["haskell", "mathematics"]
42+ci :: T3.ClientInfo
43+ci = T3.ClientInfo "Alp" "alp@foo.com" 26 ["haskell", "mathematics"]
4444
45−instance ToSample GS3.ClientInfo GS3.ClientInfo where
45+instance ToSample T3.ClientInfo T3.ClientInfo where
4646 toSample _ = Just ci
4747
48−instance ToSample GS3.Email GS3.Email where
49− toSample _ = Just (GS3.emailForClient ci)
48+instance ToSample T3.Email T3.Email where
49+ toSample _ = Just (T3.emailForClient ci)
5050
5151api :: Proxy DocsAPI
5252api = Proxy
@@ -55,12 +55,12 @@ docsBS :: ByteString
5555docsBS = encodeUtf8
5656 . pack
5757 . markdown
58− $ docsWithIntros [intro] GS3.api
58+ $ docsWithIntros [intro] T3.api
5959
6060 where intro = DocIntro "Welcome" ["This is our super webservice's API.", "Enjoy!"]
6161
6262server :: Server DocsAPI
63−server = GS3.server :<|> serveDocs
63+server = T3.server :<|> serveDocs
6464
6565 where serveDocs _ respond =
6666 respond $ responseLBS ok200 [plain] docsBS
servant-examples/getting-started/GS2.hs → servant-examples/tutorial/T2.hsrenamed+1−1
@@ -2,7 +2,7 @@
22{-# LANGUAGE TypeFamilies #-}
33{-# LANGUAGE DeriveGeneric #-}
44{-# LANGUAGE TypeOperators #-}
5−module GS2 where
5+module T2 where
66
77import Data.Aeson
88import Data.Time.Calendar
servant-examples/getting-started/GS3.hs → servant-examples/tutorial/T3.hsrenamed+1−1
@@ -2,7 +2,7 @@
22{-# LANGUAGE TypeFamilies #-}
33{-# LANGUAGE DeriveGeneric #-}
44{-# LANGUAGE TypeOperators #-}
5−module GS3 where
5+module T3 where
66
77import Control.Monad.Trans.Either
88import Data.Aeson
servant-examples/getting-started/GS4.hs → servant-examples/tutorial/T4.hsrenamed+1−1
@@ -4,7 +4,7 @@
44{-# LANGUAGE TypeOperators #-}
55{-# LANGUAGE FlexibleInstances #-}
66{-# LANGUAGE OverloadedStrings #-}
7−module GS4 where
7+module T4 where
88
99import Data.Aeson
1010import Data.Foldable (foldMap)
servant-examples/getting-started/GS5.hs → servant-examples/tutorial/T5.hsrenamed+1−1
@@ -3,7 +3,7 @@
33{-# LANGUAGE DeriveGeneric #-}
44{-# LANGUAGE TypeOperators #-}
55{-# LANGUAGE OverloadedStrings #-}
6−module GS5 where
6+module T5 where
77
88import Control.Monad.IO.Class
99import Control.Monad.Trans.Either
servant-examples/getting-started/GS6.hs → servant-examples/tutorial/T6.hsrenamed+2−2
@@ -1,7 +1,7 @@
11{-# LANGUAGE DataKinds #-}
22{-# LANGUAGE TypeFamilies #-}
33{-# LANGUAGE TypeOperators #-}
4−module GS6 where
4+module T6 where
55
66import Network.Wai
77import Servant
@@ -12,7 +12,7 @@ api :: Proxy API
1212api = Proxy
1313
1414server :: Server API
15−server = serveDirectory "getting-started"
15+server = serveDirectory "tutorial"
1616
1717app :: Application
1818app = serve api server
servant-examples/getting-started/GS7.hs → servant-examples/tutorial/T7.hsrenamed+1−1
@@ -1,7 +1,7 @@
11{-# LANGUAGE DataKinds #-}
22{-# LANGUAGE TypeFamilies #-}
33{-# LANGUAGE TypeOperators #-}
4−module GS7 where
4+module T7 where
55
66import Control.Monad.Trans.Either
77import Control.Monad.Trans.Reader
servant-examples/getting-started/GS8.hs → servant-examples/tutorial/T8.hsrenamed+2−2
@@ -1,14 +1,14 @@
11{-# LANGUAGE DataKinds #-}
22{-# LANGUAGE TypeFamilies #-}
33{-# LANGUAGE TypeOperators #-}
4−module GS8 where
4+module T8 where
55
66import Control.Monad.Trans.Either
77import Data.Aeson
88import Servant
99import Servant.Client
1010
11−import GS3
11+import T3
1212
1313position :: Int -- ^ value for "x"
1414 -> Int -- ^ value for "y"
servant-examples/getting-started/GS9.hs → servant-examples/tutorial/T9.hsrenamed+4−4
@@ -3,7 +3,7 @@
33{-# LANGUAGE DeriveGeneric #-}
44{-# LANGUAGE TypeOperators #-}
55{-# LANGUAGE OverloadedStrings #-}
6−module GS9 where
6+module T9 where
77
88import Control.Applicative
99import Control.Monad.IO.Class
@@ -89,16 +89,16 @@ server = randomPoint
8989
9090server' :: Server API'
9191server' = server
92− :<|> serveDirectory "getting-started/gs9"
92+ :<|> serveDirectory "tutorial/t9"
9393
9494apiJS :: String
9595apiJS = jsForAPI api
9696
9797writeJSFiles :: IO ()
9898writeJSFiles = do
99− writeFile "getting-started/gs9/api.js" apiJS
99+ writeFile "tutorial/t9/api.js" apiJS
100100 jq <- readFile =<< JQ.file
101− writeFile "getting-started/gs9/jq.js" jq
101+ writeFile "tutorial/t9/jq.js" jq
102102
103103app :: Application
104104app = serve api' server'
servant-examples/getting-started/gs8-main.hs → servant-examples/tutorial/t8-main.hsrenamed+1−1
@@ -1,4 +1,4 @@
1−import GS8
1+import T8
22
33main :: IO ()
44main = run
servant-examples/getting-started/gs9/index.html → servant-examples/tutorial/t9/index.htmlrenamed+1−1
@@ -3,7 +3,7 @@
33 <head>
44 <meta name="viewport" content="width=device-width, initial-scale=1">
55 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6− <title>Getting started - 9 - servant-jquery</title>
6+ <title>Tutorial - 9 - servant-jquery</title>
77 </head>
88 <body>
99 <h1>Books</h1>
servant-examples/getting-started/gs9/ui.js → servant-examples/tutorial/t9/ui.jsrenamed

The content is the same.

servant-examples/tutorial/tutorial.hsnew file+39
@@ -0,0 +1,39 @@
1+import Network.Wai
2+import Network.Wai.Handler.Warp
3+import System.Environment
4+
5+import qualified T1
6+import qualified T2
7+import qualified T3
8+import qualified T4
9+import qualified T5
10+import qualified T6
11+import qualified T7
12+import qualified T9
13+import qualified T10
14+
15+app :: String -> (Application -> IO ()) -> IO ()
16+app n f = case n of
17+ "1" -> f T1.app
18+ "2" -> f T2.app
19+ "3" -> f T3.app
20+ "4" -> f T4.app
21+ "5" -> f T5.app
22+ "6" -> f T6.app
23+ "7" -> f T7.app
24+ "8" -> f T3.app
25+ "9" -> T9.writeJSFiles >> f T9.app
26+ "10" -> f T10.app
27+ _ -> usage
28+
29+main :: IO ()
30+main = do
31+ args <- getArgs
32+ case args of
33+ [n] -> app n (run 8081)
34+ _ -> usage
35+
36+usage :: IO ()
37+usage = do
38+ putStrLn "Usage:\t tutorial N"
39+ putStrLn "\t\twhere N is the number of the example you want to run."