yaml-rpc-scotty (empty) → 1.0
raw patch · 6 files changed
+142/−0 lines, 6 filesdep +aesondep +basedep +containerssetup-changed
Dependencies added: aeson, base, containers, http-types, scotty, text, transformers, yaml, yaml-rpc
Files
- LICENSE +30/−0
- Network/YAML/Scotty.hs +24/−0
- Setup.hs +2/−0
- Test/Server.hs +17/−0
- Test/TestAPIImpl.hs +33/−0
- yaml-rpc-scotty.cabal +36/−0
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2012, IlyaPortnov++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 IlyaPortnov nor the names of other+ 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+OWNER 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.
+ Network/YAML/Scotty.hs view
@@ -0,0 +1,24 @@+{-# LANGUAGE OverloadedStrings #-}++module Network.YAML.Scotty (servePost) where++import Control.Monad.IO.Class+import Web.Scotty+import Network.HTTP.Types+import qualified Data.Text as T+import Data.Aeson hiding (json)++import Network.YAML.API+import Network.YAML.TH.Dispatcher++-- | Scotty handler. Serves each method on @/:method@.+servePost :: Dispatcher -> ScottyM ()+servePost dispatcher = post "/:method" $ do+ methodName <- param "method"+ case dispatcher methodName of+ Nothing -> status status404+ Just method -> do+ args <- jsonData+ result <- liftIO $ method args+ json result+
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ Test/Server.hs view
@@ -0,0 +1,17 @@+{-# LANGUAGE TemplateHaskell, OverloadedStrings, DeriveGeneric, StandaloneDeriving #-}++module Test.Server where++import Web.Scotty++import Network.YAML+import Network.YAML.Scotty++import Test.TestAPIImpl++$(generateDispatcher api)++main :: IO ()+main = scotty 3000 $ do+ servePost dispatcher+
+ Test/TestAPIImpl.hs view
@@ -0,0 +1,33 @@+{-# LANGUAGE TemplateHaskell, OverloadedStrings, DeriveGeneric, StandaloneDeriving #-}++module Test.TestAPIImpl where++import GHC.Generics+import qualified Data.Text as T+import Data.Aeson++import Network.YAML++data User = User {fullName :: T.Text, login :: T.Text}+ deriving (Eq, Show)++deriving instance Generic User+instance FromJSON User+instance ToJSON User++data Something = Something {smthText :: T.Text, smthList :: [T.Text]}+ deriving (Eq, Show, Generic)++instance FromJSON Something+instance ToJSON Something++sayHello :: User -> IO T.Text+sayHello user = return $ "Hello, " `T.append` fullName user `T.append` "!"++testSmth :: T.Text -> Something -> IO User+testSmth t s = return $ User {login = t `T.append` smthText s, fullName = T.intercalate " " (smthList s)}++api :: API+api = $(makeAPI "http://home.iportnov.ru/test.api" [''User, ''Something] ['sayHello, 'testSmth])++$(writeAPI "test.api" "http://home.iportnov.ru/test.api" [''User, ''Something] ['sayHello, 'testSmth])
+ yaml-rpc-scotty.cabal view
@@ -0,0 +1,36 @@+Name: yaml-rpc-scotty++Version: 1.0++Synopsis: Scotty server backend for yaml-rpc+Description: This package provides Scotty-based server backend for yaml-rpc package.+Homepage: http://redmine.iportnov.ru/projects/yaml-rpc+License: BSD3+License-file: LICENSE+Author: Ilya V. Portnov+Maintainer: portnov84@rambler.ru+Category: Network+Build-type: Simple+Cabal-version: >= 1.8++Library+ Exposed-modules: Network.YAML.Scotty+ Build-depends: base >= 3 && <= 5,+ transformers >= 0.3.0.0,+ aeson >= 0.7.0.3,+ yaml,+ containers,+ text >= 1.1.1.3,+ http-types >= 0.8.5,+ scotty >= 0.8.0,+ yaml-rpc >= 1.0++ Other-modules: Test.Server,+ Test.TestAPIImpl++Source-repository head+ type: git+ location: git@github.com:portnov/yaml-rpc.git+++