on master help sign in
Bring in test project
commit8f8b77652374f533a67fa4ce438a1edffe7f5798 authorGreg Hale <imalsogreg@gmail.com> dateSat 6 Feb 2016, 22:44 (11 years ago) parente302b6a
15 files changed+261−77
.gitmodules+6 deps/reflex-dom+1 deps/servant-snap+1 exec/Server.hs−77 init-sandbox.sh+40 test/back/API.hs+1 test/back/LICENSE+30 test/back/Main.hs+57 test/back/back.cabal+24 test/common/API.hs+8 test/front/API.hs+1 test/front/LICENSE+30 test/front/Main.hs+28 test/front/default.nix+10 test/front/front.cabal+24
.gitmodules+6
@@ -7,3 +7,9 @@
77[submodule "deps/servant"]
88 path = deps/servant
99 url = https://github.com/haskell-servant/servant.git
10+[submodule "deps/servant-snap"]
11+ path = deps/servant-snap
12+ url = https://github.com/haskell-servant/servant-snap
13+[submodule "deps/reflex-dom"]
14+ path = deps/reflex-dom
15+ url = https://github.com/ryantrinkle/reflex-dom
deps/reflex-domnew file+1

Submodule changed.

deps/servant-snapnew file+1

Submodule changed.

exec/Server.hsdeleted−77
@@ -1,77 +0,0 @@
1−{-# LANGUAGE DataKinds #-}
2−{-# LANGUAGE DeriveGeneric #-}
3−{-# LANGUAGE OverloadedStrings #-}
4−{-# LANGUAGE PolyKinds #-}
5−{-# LANGUAGE TypeFamilies #-}
6−{-# LANGUAGE TypeOperators #-}
7−
8−import Data.Aeson
9−import Data.Monoid
10−import Data.Proxy
11−import Data.Text
12−import GHC.Generics
13−import Network.Wai
14−import Network.Wai.Handler.Warp
15−
16−import Servant
17−import API
18−
19−-- * Example
20−
21−-- | A greet message data type
22−newtype Greet = Greet { _msg :: Text }
23− deriving (Generic, Show)
24−
25− instance FromJSON Greet
26−instance ToJSON Greet
27−
28−-- API specification
29−type TestApi =
30− -- GET /hello/:name?capital={true, false} returns a Greet as JSON
31− "hello" :> Capture "name" Text :> QueryParam "capital" Bool :> Get '[JSON] Greet
32−
33− -- POST /greet with a Greet as JSON in the request body,
34− -- returns a Greet as JSON
35− :<|> "greet" :> ReqBody '[JSON] Greet :> Post '[JSON] Greet
36−
37− -- DELETE /greet/:greetid
38− :<|> "greet" :> Capture "greetid" Text :> Delete '[JSON] ()
39−
40− testApi :: Proxy TestApi
41− testApi = Proxy
42−
43−
44−server1 :: Server API
45−server1 = return $ Right ()
46−
47− -- Server-side handlers.
48−--
49−-- There's one handler per endpoint, which, just like in the type
50−-- that represents the API, are glued together using :<|>.
51−--
52−-- Each handler runs in the 'ExceptT ServantErr IO' monad.
53−server :: Server TestApi
54−server = helloH :<|> postGreetH :<|> deleteGreetH
55−
56− where helloH name Nothing = helloH name (Just False)
57− helloH name (Just False) = return . Greet $ "Hello, " <> name
58− helloH name (Just True) = return . Greet . toUpper $ "Hello, " <> name
59−
60− postGreetH greet = return greet
61−
62− deleteGreetH _ = return ()
63−
64− -- Turn the server into a WAI app. 'serve' is provided by servant,
65−-- more precisely by the Servant.Server module.
66−test :: Application
67−test = serve testApi EmptyConfig server
68−
69−-- Run the server.
70−--
71−-- 'run' comes from Network.Wai.Handler.Warp
72−runTestServer :: Port -> IO ()
73−runTestServer port = run port test
74−
75−-- Put this all to work!
76−main :: IO ()
77−main = runTestServer 8000
init-sandbox.shnew file+40
@@ -0,0 +1,40 @@
1+#! /bin/sh
2+
3+cabal sandbox init
4+
5+cabal sandbox add-source deps/snaplet-postgresql-simple
6+
7+#! /bin/sh
8+
9+cabal sandbox init
10+
11+echo "Depend on snap-1.0 from github. Move to Hackage version when snap-1.0 is released"
12+cabal sandbox add-source deps/servant-snap/deps/snap/deps/io-streams
13+cabal sandbox add-source deps/servant-snap/deps/snap/deps/io-streams-haproxy
14+cabal sandbox add-source deps/servant-snap/deps/snap/deps/snap-core
15+cabal sandbox add-source deps/servant-snap/deps/snap/deps/snap-server
16+cabal sandbox add-source deps/servant-snap/deps/snap/deps/xmlhtml
17+cabal sandbox add-source deps/servant-snap/deps/snap/deps/heist
18+cabal sandbox add-source deps/servant-snap/deps/snap-loader-static
19+cabal sandbox add-source deps/servant-snap/deps/snap-loader-static
20+cabal sandbox add-source deps/servant-snap/deps/snap
21+cabal sandbox add-source deps/servant-snap/deps/hspec-snap
22+
23+echo "Depend on particular servant branch with (Raw m a) changes"
24+echo "TODO: Move to hackage version when servant-0.5 is released"
25+cabal sandbox add-source deps/servant-snap/deps/servant/servant
26+cabal sandbox add-source deps/servant-snap/deps/servant/servant-docs
27+cabal sandbox add-source deps/servant-snap/deps/servant/servant-client
28+cabal sandbox add-source deps/servant-snap/deps/servant/servant-blaze
29+cabal sandbox add-source deps/servant-snap/deps/servant/servant-js
30+cabal sandbox add-source deps/servant-snap/deps/servant/servant-lucid
31+cabal sandbox add-source deps/servant-snap/deps/servant/servant-mock
32+
33+cabal sandbox add-source deps/servant-snap
34+cabal sandbox add-source deps/reflex-dom
35+cabal sandbox add-source deps/reflex-dom-contrib
36+
37+cabal sandbox add-source .
38+
39+cd test/front && cabal sandbox init --sandbox=../../.cabal-sandbox && cd ../..
40+cd test/back && cabal sandbox init --sandbox=../../.cabal-sandbox && cd ../..
test/back/API.hsnew file+1
@@ -0,0 +1 @@
1+../common/API.hs
test/back/LICENSEnew file+30
@@ -0,0 +1,30 @@
1+Copyright (c) 2016, Greg Hale
2+
3+All rights reserved.
4+
5+Redistribution and use in source and binary forms, with or without
6+modification, are permitted provided that the following conditions are met:
7+
8+ * Redistributions of source code must retain the above copyright
9+ notice, this list of conditions and the following disclaimer.
10+
11+ * Redistributions in binary form must reproduce the above
12+ copyright notice, this list of conditions and the following
13+ disclaimer in the documentation and/or other materials provided
14+ with the distribution.
15+
16+ * Neither the name of Greg Hale nor the names of other
17+ contributors may be used to endorse or promote products derived
18+ from this software without specific prior written permission.
19+
20+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
test/back/Main.hsnew file+57
@@ -0,0 +1,57 @@
1+{-# LANGUAGE DataKinds #-}
2+{-# LANGUAGE DeriveGeneric #-}
3+{-# LANGUAGE OverloadedStrings #-}
4+{-# LANGUAGE PolyKinds #-}
5+{-# LANGUAGE TypeFamilies #-}
6+{-# LANGUAGE TypeOperators #-}
7+
8+import Data.Aeson
9+import Data.Monoid
10+import Data.Proxy
11+import Data.Text
12+import GHC.Generics
13+import Snap.Http.Server
14+import Snap.Core
15+import Servant.Server.Internal.SnapShims
16+
17+import Servant
18+import Servant.Server
19+import API
20+
21+-- * Example
22+
23+-- | A greet message data type
24+newtype Greet = Greet { _msg :: Text }
25+ deriving (Generic, Show)
26+
27+instance FromJSON Greet
28+instance ToJSON Greet
29+
30+testApi :: Proxy API
31+testApi = Proxy
32+
33+-- Server-side handlers.
34+--
35+-- There's one handler per endpoint, which, just like in the type
36+-- that represents the API, are glued together using :<|>.
37+--
38+-- Each handler runs in the 'ExceptT ServantErr IO' monad.
39+server :: Server API Snap
40+server = return ()
41+
42+ where helloH name Nothing = helloH name (Just False)
43+ helloH name (Just False) = return . Greet $ "Hello, " <> name
44+ helloH name (Just True) = return . Greet . toUpper $ "Hello, " <> name
45+
46+ postGreetH greet = return greet
47+
48+ deleteGreetH _ = return ()
49+
50+-- Turn the server into a WAI app. 'serve' is provided by servant,
51+-- more precisely by the Servant.Server module.
52+test :: Application Snap
53+test = serve testApi server
54+
55+-- Put this all to work!
56+main :: IO ()
57+main = quickHttpServe $ applicationToSnap (serve testApi server)
test/back/back.cabalnew file+24
@@ -0,0 +1,24 @@
1+-- Initial back.cabal generated by cabal init. For further documentation,
2+-- see http://haskell.org/cabal/users-guide/
3+
4+name: back
5+version: 0.1.0.0
6+-- synopsis:
7+-- description:
8+license: BSD3
9+license-file: LICENSE
10+author: Greg Hale
11+maintainer: imalsogreg@gmail.com
12+-- copyright:
13+-- category:
14+build-type: Simple
15+-- extra-source-files:
16+cabal-version: >=1.10
17+
18+executable back
19+ main-is: Main.hs
20+ -- other-modules:
21+ -- other-extensions:
22+ build-depends: aeson, base >=4.8 && <4.9, snap, snap-server, snap-core, servant, servant-snap, text
23+ -- hs-source-dirs:
24+ default-language: Haskell2010
test/common/API.hsnew file+8
@@ -0,0 +1,8 @@
1+{-# LANGUAGE DataKinds #-}
2+{-# LANGUAGE TypeOperators #-}
3+
4+module API where
5+
6+import Servant.API
7+
8+type API = Get '[JSON] ()
test/front/API.hsnew file+1
@@ -0,0 +1 @@
1+../common/API.hs
test/front/LICENSEnew file+30
@@ -0,0 +1,30 @@
1+Copyright (c) 2016, Greg Hale
2+
3+All rights reserved.
4+
5+Redistribution and use in source and binary forms, with or without
6+modification, are permitted provided that the following conditions are met:
7+
8+ * Redistributions of source code must retain the above copyright
9+ notice, this list of conditions and the following disclaimer.
10+
11+ * Redistributions in binary form must reproduce the above
12+ copyright notice, this list of conditions and the following
13+ disclaimer in the documentation and/or other materials provided
14+ with the distribution.
15+
16+ * Neither the name of Greg Hale nor the names of other
17+ contributors may be used to endorse or promote products derived
18+ from this software without specific prior written permission.
19+
20+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
test/front/Main.hsnew file+28
@@ -0,0 +1,28 @@
1+{-# LANGUAGE ScopedTypeVariables #-}
2+{-# LANGUAGE RankNTypes #-}
3+
4+module Main where
5+
6+import Servant.Reflex
7+import API
8+import Data.Proxy
9+import Reflex.Dom
10+import Reflex.Dom.Contrib.Xhr
11+
12+api :: Proxy API
13+api = Proxy
14+
15+url :: BaseUrl
16+url = BaseUrl Http "localhost" 8000 ""
17+
18+main :: IO ()
19+main = mainWidget run
20+
21+run :: forall t m. MonadWidget t m => m ()
22+run = do
23+ let (getUnit :: Event t () -> m (Event t ((),()))) = client api url
24+ b :: Event t () <- button "Get unit"
25+ res :: Event t ((),()) <- getUnit b
26+ c <- foldDyn (\_ (n :: Int) -> succ n) 0 res
27+ display c
28+
test/front/default.nixnew file+10
@@ -0,0 +1,10 @@
1+{ mkDerivation, base, servant, servant-reflex, stdenv }:
2+mkDerivation {
3+ pname = "front";
4+ version = "0.1.0.0";
5+ src = ./.;
6+ isLibrary = false;
7+ isExecutable = true;
8+ executableHaskellDepends = [ base servant servant-reflex ];
9+ license = stdenv.lib.licenses.bsd3;
10+}
test/front/front.cabalnew file+24
@@ -0,0 +1,24 @@
1+-- Initial front.cabal generated by cabal init. For further documentation,
2+-- see http://haskell.org/cabal/users-guide/
3+
4+name: front
5+version: 0.1.0.0
6+-- synopsis:
7+-- description:
8+license: BSD3
9+license-file: LICENSE
10+author: Greg Hale
11+maintainer: imalsogreg@gmail.com
12+-- copyright:
13+-- category:
14+build-type: Simple
15+-- extra-source-files:
16+cabal-version: >=1.10
17+
18+executable front
19+ main-is: Main.hs
20+ other-modules: API
21+ other-extensions: ScopedTypeVariables, RankNTypes
22+ build-depends: base >=4.8 && <4.9, servant, servant-reflex
23+ -- hs-source-dirs:
24+ default-language: Haskell2010