summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndyGill <>2016-02-09 23:13:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2016-02-09 23:13:00 (GMT)
commit40bf399aec92f59866fd3659ffe14a9e7c66fe5b (patch)
treedbcc3fa463809c268d41cd5a72df50e597182017
version 0.20.2
-rw-r--r--Control/Remote/Monad/JSON/Server.hs41
-rw-r--r--LICENSE28
-rw-r--r--README.md2
-rw-r--r--Setup.hs2
-rw-r--r--remote-json-server.cabal35
5 files changed, 108 insertions, 0 deletions
diff --git a/Control/Remote/Monad/JSON/Server.hs b/Control/Remote/Monad/JSON/Server.hs
new file mode 100644
index 0000000..4b5d207
--- /dev/null
+++ b/Control/Remote/Monad/JSON/Server.hs
@@ -0,0 +1,41 @@
+{-# LANGUAGE GADTs #-}
+{-# LANGUAGE RankNTypes #-}
+{-# LANGUAGE OverloadedStrings #-}
+{-# LANGUAGE TypeOperators #-}
+
+module Control.Remote.Monad.JSON.Server
+ ( -- * Ways of building the actionable parts of a Scotty server
+ scottyReceiveAPI
+ , serverReceiveAPI
+ ) where
+
+import Control.Remote.Monad.JSON.Router (ReceiveAPI(..))
+import Control.Monad.IO.Class
+import Control.Natural
+import Data.Aeson()
+import Data.Default.Class (def)
+import Web.Scotty (scottyOpts)
+import Web.Scotty.Trans as T
+import Network.Wai.Handler.Warp (setPort)
+
+
+-- | A way of building client 'SendAPI' support, using wreq.
+{-
+ serverReceiveAPI :: forall e (m :: * -> *) (t :: * -> *) a.
+ (Foldable t, ToJSON a, MonadIO m, ScottyError e) =>
+ (ReceiveAPI (Maybe Value) -> IO (t a)) -> ActionT e m ()
+-}
+-- | Blocking function that listens on a specific port, to a specific path.
+serverReceiveAPI :: Int -> String -> (ReceiveAPI :~> IO) -> IO ()
+serverReceiveAPI port path f = scottyOpts opts $ post (literal path) $ scottyReceiveAPI f
+ where opts = def { verbose = 0, settings = setPort port (settings def) }
+
+-- | Build the 'ActionT' action for Scotty.
+scottyReceiveAPI :: (ScottyError e, MonadIO m)
+ => (ReceiveAPI :~> IO) -> ActionT e m ()
+scottyReceiveAPI (Nat f) = do
+ d <- jsonData
+ r <- liftIO $ f $ Receive $ d
+ case r of
+ Nothing -> return ()
+ Just v -> T.json v
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..4b57e9f
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,28 @@
+Copyright (c) 2015, Functional Programming at the University of Kansas
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+* Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+* Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+* Neither the name of remote-json nor the names of its
+ contributors may be used to endorse or promote products derived from
+ this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..3877152
--- /dev/null
+++ b/README.md
@@ -0,0 +1,2 @@
+A sub-package of remote-json that provides the ReceiveAPI capabilities.
+
diff --git a/Setup.hs b/Setup.hs
new file mode 100644
index 0000000..9a994af
--- /dev/null
+++ b/Setup.hs
@@ -0,0 +1,2 @@
+import Distribution.Simple
+main = defaultMain
diff --git a/remote-json-server.cabal b/remote-json-server.cabal
new file mode 100644
index 0000000..9bf0d71
--- /dev/null
+++ b/remote-json-server.cabal
@@ -0,0 +1,35 @@
+name: remote-json-server
+version: 0.2
+synopsis: Web server wrapper for remote-json
+description: Web server, using scotty, for the JSON RPC protocol.
+license: BSD3
+license-file: LICENSE
+author: Justin Dawson and Andy Gill
+maintainer: JDawson@ku.edu
+copyright: (c) 2016 The University of Kansas
+category: Network
+build-type: Simple
+extra-source-files: README.md
+tested-with: GHC == 7.10.3
+cabal-version: >=1.10
+
+source-repository head
+ type: git
+ location: git://github.com/ku-fpg/remote-json
+
+library
+ exposed-modules: Control.Remote.Monad.JSON.Server
+
+ -- other-modules:
+ build-depends: aeson >= 0.8 && < 0.12
+ , base >= 4 && < 5
+ , data-default-class == 0.0.1
+ , natural-transformation >= 0.3.1 && < 0.4
+ , remote-json >= 0.2 && < 0.3
+ , warp >= 3.2 && < 3.3
+ , scotty >= 0.10
+ , text >= 1.2 && < 1.3
+ , transformers >= 0.4 && < 0.6
+ hs-source-dirs: .
+ default-language: Haskell2010
+ ghc-options: -Wall