on master help sign in
getting-started -> tutorial
39d114aAlp Mestanogullari
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
13build-type: Simple
13build-type: Simple
14cabal-version: >=1.10
14cabal-version: >=1.10
15
15
16−executable getting-started
16+executable tutorial
17− main-is: getting-started.hs
17+ main-is: tutorial.hs
18− other-modules: GS1, GS2, GS3, GS4, GS5, GS6, GS7, GS8, GS9, GS10
18+ other-modules: T1, T2, T3, T4, T5, T6, T7, T8, T9, T10
19 build-depends:
19 build-depends:
20 aeson >= 0.8
20 aeson >= 0.8
21 , base >= 4.7
21 , base >= 4.7
@@ -36,12 +36,12 @@ executable getting-started
36 , transformers
36 , transformers
37 , wai
37 , wai
38 , warp
38 , warp
39− hs-source-dirs: getting-started
39+ hs-source-dirs: tutorial
40 default-language: Haskell2010
40 default-language: Haskell2010
41
41
42−executable gs8-main
42+executable t8-main
43− main-is: gs8-main.hs
43+ main-is: t8-main.hs
44− hs-source-dirs: getting-started
44+ hs-source-dirs: tutorial
45 default-language: Haskell2010
45 default-language: Haskell2010
46 build-depends:
46 build-depends:
47 aeson
47 aeson
servant-examples/getting-started/GS1.hs → servant-examples/tutorial/T1.hsrenamed+1−1
@@ -2,7 +2,7 @@
2{-# LANGUAGE TypeFamilies #-}
2{-# LANGUAGE TypeFamilies #-}
3{-# LANGUAGE DeriveGeneric #-}
3{-# LANGUAGE DeriveGeneric #-}
4{-# LANGUAGE TypeOperators #-}
4{-# LANGUAGE TypeOperators #-}
5−module GS1 where
5+module T1 where
6
6
7import Data.Aeson
7import Data.Aeson
8import Data.Time.Calendar
8import Data.Time.Calendar
servant-examples/getting-started/GS10.hs → servant-examples/tutorial/T10.hsrenamed+15−15
@@ -4,7 +4,7 @@
4{-# LANGUAGE FlexibleInstances #-}
4{-# LANGUAGE FlexibleInstances #-}
5{-# LANGUAGE OverloadedStrings #-}
5{-# LANGUAGE OverloadedStrings #-}
6{-# LANGUAGE MultiParamTypeClasses #-}
6{-# LANGUAGE MultiParamTypeClasses #-}
7−module GS10 where
7+module T10 where
8
8
9import Data.ByteString.Lazy (ByteString)
9import Data.ByteString.Lazy (ByteString)
10import Data.Text.Lazy (pack)
10import Data.Text.Lazy (pack)
@@ -13,9 +13,9 @@ import Network.HTTP.Types
13import Network.Wai
13import Network.Wai
14import Servant
14import Servant
15import Servant.Docs
15import Servant.Docs
16−import qualified GS3
16+import qualified T3
17
17
18−type DocsAPI = GS3.API :<|> Raw
18+type DocsAPI = T3.API :<|> Raw
19
19
20instance ToCapture (Capture "x" Int) where
20instance ToCapture (Capture "x" Int) where
21 toCapture _ = DocCapture "x" "(integer) position on the x axis"
21 toCapture _ = DocCapture "x" "(integer) position on the x axis"
@@ -23,8 +23,8 @@ instance ToCapture (Capture "x" Int) where
23instance ToCapture (Capture "y" Int) where
23instance ToCapture (Capture "y" Int) where
24 toCapture _ = DocCapture "y" "(integer) position on the y axis"
24 toCapture _ = DocCapture "y" "(integer) position on the y axis"
25
25
26−instance ToSample GS3.Position GS3.Position where
26+instance ToSample T3.Position T3.Position where
27− toSample _ = Just (GS3.Position 3 14)
27+ toSample _ = Just (T3.Position 3 14)
28
28
29instance ToParam (QueryParam "name" String) where
29instance ToParam (QueryParam "name" String) where
30 toParam _ =
30 toParam _ =
@@ -33,20 +33,20 @@ instance ToParam (QueryParam "name" String) where
33 "Name of the person to say hello to."
33 "Name of the person to say hello to."
34 Normal
34 Normal
35
35
36−instance ToSample GS3.HelloMessage GS3.HelloMessage where
36+instance ToSample T3.HelloMessage T3.HelloMessage where
37 toSamples _ =
37 toSamples _ =
38− [ ("When a value is provided for 'name'", GS3.HelloMessage "Hello, Alp")
38+ [ ("When a value is provided for 'name'", T3.HelloMessage "Hello, Alp")
39− , ("When 'name' is not specified", GS3.HelloMessage "Hello, anonymous coward")
39+ , ("When 'name' is not specified", T3.HelloMessage "Hello, anonymous coward")
40 ]
40 ]
41
41
42−ci :: GS3.ClientInfo
42+ci :: T3.ClientInfo
43−ci = GS3.ClientInfo "Alp" "alp@foo.com" 26 ["haskell", "mathematics"]
43+ci = T3.ClientInfo "Alp" "alp@foo.com" 26 ["haskell", "mathematics"]
44
44
45−instance ToSample GS3.ClientInfo GS3.ClientInfo where
45+instance ToSample T3.ClientInfo T3.ClientInfo where
46 toSample _ = Just ci
46 toSample _ = Just ci
47
47
48−instance ToSample GS3.Email GS3.Email where
48+instance ToSample T3.Email T3.Email where
49− toSample _ = Just (GS3.emailForClient ci)
49+ toSample _ = Just (T3.emailForClient ci)
50
50
51api :: Proxy DocsAPI
51api :: Proxy DocsAPI
52api = Proxy
52api = Proxy
@@ -55,12 +55,12 @@ docsBS :: ByteString
55docsBS = encodeUtf8
55docsBS = encodeUtf8
56 . pack
56 . pack
57 . markdown
57 . markdown
58− $ docsWithIntros [intro] GS3.api
58+ $ docsWithIntros [intro] T3.api
59
59
60 where intro = DocIntro "Welcome" ["This is our super webservice's API.", "Enjoy!"]
60 where intro = DocIntro "Welcome" ["This is our super webservice's API.", "Enjoy!"]
61
61
62server :: Server DocsAPI
62server :: Server DocsAPI
63−server = GS3.server :<|> serveDocs
63+server = T3.server :<|> serveDocs
64
64
65 where serveDocs _ respond =
65 where serveDocs _ respond =
66 respond $ responseLBS ok200 [plain] docsBS
66 respond $ responseLBS ok200 [plain] docsBS
servant-examples/getting-started/GS2.hs → servant-examples/tutorial/T2.hsrenamed+1−1
@@ -2,7 +2,7 @@
2{-# LANGUAGE TypeFamilies #-}
2{-# LANGUAGE TypeFamilies #-}
3{-# LANGUAGE DeriveGeneric #-}
3{-# LANGUAGE DeriveGeneric #-}
4{-# LANGUAGE TypeOperators #-}
4{-# LANGUAGE TypeOperators #-}
5−module GS2 where
5+module T2 where
6
6
7import Data.Aeson
7import Data.Aeson
8import Data.Time.Calendar
8import Data.Time.Calendar
servant-examples/getting-started/GS3.hs → servant-examples/tutorial/T3.hsrenamed+1−1
@@ -2,7 +2,7 @@
2{-# LANGUAGE TypeFamilies #-}
2{-# LANGUAGE TypeFamilies #-}
3{-# LANGUAGE DeriveGeneric #-}
3{-# LANGUAGE DeriveGeneric #-}
4{-# LANGUAGE TypeOperators #-}
4{-# LANGUAGE TypeOperators #-}
5−module GS3 where
5+module T3 where
6
6
7import Control.Monad.Trans.Either
7import Control.Monad.Trans.Either
8import Data.Aeson
8import Data.Aeson
servant-examples/getting-started/GS4.hs → servant-examples/tutorial/T4.hsrenamed+1−1
@@ -4,7 +4,7 @@
4{-# LANGUAGE TypeOperators #-}
4{-# LANGUAGE TypeOperators #-}
5{-# LANGUAGE FlexibleInstances #-}
5{-# LANGUAGE FlexibleInstances #-}
6{-# LANGUAGE OverloadedStrings #-}
6{-# LANGUAGE OverloadedStrings #-}
7−module GS4 where
7+module T4 where
8
8
9import Data.Aeson
9import Data.Aeson
10import Data.Foldable (foldMap)
10import Data.Foldable (foldMap)
servant-examples/getting-started/GS5.hs → servant-examples/tutorial/T5.hsrenamed+1−1
@@ -3,7 +3,7 @@
3{-# LANGUAGE DeriveGeneric #-}
3{-# LANGUAGE DeriveGeneric #-}
4{-# LANGUAGE TypeOperators #-}
4{-# LANGUAGE TypeOperators #-}
5{-# LANGUAGE OverloadedStrings #-}
5{-# LANGUAGE OverloadedStrings #-}
6−module GS5 where
6+module T5 where
7
7
8import Control.Monad.IO.Class
8import Control.Monad.IO.Class
9import Control.Monad.Trans.Either
9import Control.Monad.Trans.Either
servant-examples/getting-started/GS6.hs → servant-examples/tutorial/T6.hsrenamed+2−2
@@ -1,7 +1,7 @@
1{-# LANGUAGE DataKinds #-}
1{-# LANGUAGE DataKinds #-}
2{-# LANGUAGE TypeFamilies #-}
2{-# LANGUAGE TypeFamilies #-}
3{-# LANGUAGE TypeOperators #-}
3{-# LANGUAGE TypeOperators #-}
4−module GS6 where
4+module T6 where
5
5
6import Network.Wai
6import Network.Wai
7import Servant
7import Servant
@@ -12,7 +12,7 @@ api :: Proxy API
12api = Proxy
12api = Proxy
13
13
14server :: Server API
14server :: Server API
15−server = serveDirectory "getting-started"
15+server = serveDirectory "tutorial"
16
16
17app :: Application
17app :: Application
18app = serve api server
18app = serve api server
servant-examples/getting-started/GS7.hs → servant-examples/tutorial/T7.hsrenamed+1−1
@@ -1,7 +1,7 @@
1{-# LANGUAGE DataKinds #-}
1{-# LANGUAGE DataKinds #-}
2{-# LANGUAGE TypeFamilies #-}
2{-# LANGUAGE TypeFamilies #-}
3{-# LANGUAGE TypeOperators #-}
3{-# LANGUAGE TypeOperators #-}
4−module GS7 where
4+module T7 where
5
5
6import Control.Monad.Trans.Either
6import Control.Monad.Trans.Either
7import Control.Monad.Trans.Reader
7import Control.Monad.Trans.Reader
servant-examples/getting-started/GS8.hs → servant-examples/tutorial/T8.hsrenamed+2−2
@@ -1,14 +1,14 @@
1{-# LANGUAGE DataKinds #-}
1{-# LANGUAGE DataKinds #-}
2{-# LANGUAGE TypeFamilies #-}
2{-# LANGUAGE TypeFamilies #-}
3{-# LANGUAGE TypeOperators #-}
3{-# LANGUAGE TypeOperators #-}
4−module GS8 where
4+module T8 where
5
5
6import Control.Monad.Trans.Either
6import Control.Monad.Trans.Either
7import Data.Aeson
7import Data.Aeson
8import Servant
8import Servant
9import Servant.Client
9import Servant.Client
10
10
11−import GS3
11+import T3
12
12
13position :: Int -- ^ value for "x"
13position :: Int -- ^ value for "x"
14 -> Int -- ^ value for "y"
14 -> Int -- ^ value for "y"
servant-examples/getting-started/GS9.hs → servant-examples/tutorial/T9.hsrenamed+4−4
@@ -3,7 +3,7 @@
3{-# LANGUAGE DeriveGeneric #-}
3{-# LANGUAGE DeriveGeneric #-}
4{-# LANGUAGE TypeOperators #-}
4{-# LANGUAGE TypeOperators #-}
5{-# LANGUAGE OverloadedStrings #-}
5{-# LANGUAGE OverloadedStrings #-}
6−module GS9 where
6+module T9 where
7
7
8import Control.Applicative
8import Control.Applicative
9import Control.Monad.IO.Class
9import Control.Monad.IO.Class
@@ -89,16 +89,16 @@ server = randomPoint
89
89
90server' :: Server API'
90server' :: Server API'
91server' = server
91server' = server
92− :<|> serveDirectory "getting-started/gs9"
92+ :<|> serveDirectory "tutorial/t9"
93
93
94apiJS :: String
94apiJS :: String
95apiJS = jsForAPI api
95apiJS = jsForAPI api
96
96
97writeJSFiles :: IO ()
97writeJSFiles :: IO ()
98writeJSFiles = do
98writeJSFiles = do
99− writeFile "getting-started/gs9/api.js" apiJS
99+ writeFile "tutorial/t9/api.js" apiJS
100 jq <- readFile =<< JQ.file
100 jq <- readFile =<< JQ.file
101− writeFile "getting-started/gs9/jq.js" jq
101+ writeFile "tutorial/t9/jq.js" jq
102
102
103app :: Application
103app :: Application
104app = serve api' server'
104app = 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
2
2
3main :: IO ()
3main :: IO ()
4main = run
4main = run
servant-examples/getting-started/gs9/index.html → servant-examples/tutorial/t9/index.htmlrenamed+1−1
@@ -3,7 +3,7 @@
3 <head>
3 <head>
4 <meta name="viewport" content="width=device-width, initial-scale=1">
4 <meta name="viewport" content="width=device-width, initial-scale=1">
5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
5 <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>
7 </head>
7 </head>
8 <body>
8 <body>
9 <h1>Books</h1>
9 <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."