colorless-scotty (empty) → 0.0.0
raw patch · 5 files changed
+143/−0 lines, 5 filesdep +aesondep +basedep +colorless
Dependencies added: aeson, base, colorless, mtl, scotty, text, wai
Files
- LICENSE +29/−0
- README.md +5/−0
- colorless-scotty.cabal +35/−0
- library/Colorless/Server/Scotty.hs +50/−0
- package.yaml +24/−0
+ LICENSE view
@@ -0,0 +1,29 @@+BSD 3-Clause License++Copyright (c) 2017, Joe Vargas+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 the copyright holder 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.
+ README.md view
@@ -0,0 +1,5 @@+# colorless-scotty++Quick and simple glue code for server-side Colorless with HTTP.++In conjunction with `scotty`, `colorless-scotty` can be an addon for generated server-side code.
+ colorless-scotty.cabal view
@@ -0,0 +1,35 @@+-- This file has been generated from package.yaml by hpack version 0.17.0.+--+-- see: https://github.com/sol/hpack++name: colorless-scotty+version: 0.0.0+synopsis: Scotty server add-on for Colorless+description: Scotty server add-on for Colorless+category: Web+maintainer: Joe Vargas+license: BSD3+license-file: LICENSE+build-type: Simple+cabal-version: >= 1.10++extra-source-files:+ package.yaml+ README.md++library+ hs-source-dirs:+ library+ default-extensions: OverloadedStrings NamedFieldPuns+ ghc-options: -Wall+ build-depends:+ aeson+ , base >= 4.7 && < 5+ , colorless+ , scotty+ , text+ , mtl+ , wai+ exposed-modules:+ Colorless.Server.Scotty+ default-language: Haskell2010
+ library/Colorless/Server/Scotty.hs view
@@ -0,0 +1,50 @@+module Colorless.Server.Scotty+ ( runServer+ , sendResponse+ , sendResponseSingleton+ , getSpec+ , ScottyError+ , ScottyT+ , WaiResponse+ ) where++import qualified Network.Wai as Wai+import Web.Scotty.Trans+import Control.Monad.Trans (lift)+import Colorless.Server (Pull(..), RuntimeThrower, Request, Response, Version, Major, Minor)+import Colorless.Imports+import Colorless.Endpoint++type WaiResponse = Wai.Response++runServer+ :: (MonadIO m, RuntimeThrower m, MonadIO n)+ => Pull+ -> (m WaiResponse -> IO WaiResponse)+ -> ScottyT e m ()+ -> n ()+runServer Pull{port} = scottyT port++sendResponse+ :: (ScottyError e, MonadIO m, RuntimeThrower m)+ => Pull+ -> Map Major (Minor, Request -> m Response)+ -> ScottyT e m ()+sendResponse Pull{path} handlerMap = post (literal $ fromText path) $ do+ req <- jsonData+ resp <- lift $ runColorless handlerMap req+ json resp++sendResponseSingleton+ :: (ScottyError e, MonadIO m, RuntimeThrower m)+ => Pull+ -> Version+ -> (Request -> m Response)+ -> ScottyT e m ()+sendResponseSingleton Pull{path} version handler = post (literal $ fromText path) $ do+ req <- jsonData+ resp <- lift $ runColorlessSingleton version handler req+ json resp++getSpec :: (ScottyError e, MonadIO m) => Value -> Pull -> ScottyT e m ()+getSpec spec Pull{path} = get (literal $ fromText path) $ json spec
+ package.yaml view
@@ -0,0 +1,24 @@+name: colorless-scotty+version: '0.0.0'+category: Web+synopsis: Scotty server add-on for Colorless+description: Scotty server add-on for Colorless+maintainer: Joe Vargas+license: BSD3+extra-source-files:+- package.yaml+- README.md+ghc-options: -Wall+default-extensions:+- OverloadedStrings+- NamedFieldPuns+library:+ dependencies:+ - aeson+ - base >= 4.7 && < 5+ - colorless+ - scotty+ - text+ - mtl+ - wai+ source-dirs: library