Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

remove first try

  • Loading branch information...
commit 4de3884ddae9a1fde772fd0392c0797509e13fda 1 parent d8fe8cf
@obcode obcode authored
View
30 LICENSE
@@ -1,30 +0,0 @@
-Copyright (c)2011, Oliver Braun
-
-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 Oliver Braun 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.
View
37 README
@@ -1,37 +0,0 @@
- _ _ _ _ _
- ___ _ __ (_)_ __(_) |_ __| | __ _| |_ __ _
- / __| '_ \| | '__| | __|____ / _` |/ _` | __/ _` |
- \__ \ |_) | | | | | ||_____| (_| | (_| | || (_| |
- |___/ .__/|_|_| |_|\__| \__,_|\__,_|\__\__,_|
- |_|
-
-This will become the RESTful service for all data published by the spirit@fhs apps.
-
-Requirements:
-
-- the Haskell platform from http://hackage.haskell.org/platform/
-
-or at least:
-
-- GHC from http://haskell.org/ghc/
-- Cabal-install from http://www.haskell.org/cabal/
-
-then simply do
-
-$ cabal configure
-$ cabal build
-
-start the server:
-
-$ ./dist/build/spiritservice/spiritservice
-
-start the simple client:
-
-$ ./dist/build/simpleclient/simpleclient
-
-and then start editing and help improving!
-
-...waiting for pull requests...
-
-Intial version was taken from the yesod blog: http://www.yesodweb.com/blog/2011/06/cookbook-part-2
-
View
36 data.cabal
@@ -1,36 +0,0 @@
-Name: data
-Version: 0.1
-Synopsis: RESTful data service for spirit apps
-Homepage: http://pads.fh-schmalkalden.de/spirit.html
-License: BSD3
-License-file: LICENSE
-Author: Oliver Braun
-Maintainer: ob@obraun.net
-Category: Misc
-Build-type: Simple
-Cabal-version: >=1.2
-
-Executable spiritservice
- hs-source-dirs: src
- Main-is: SpiritService.hs
- Build-depends: base >= 4.2 && < 5,
- blaze-builder,
- http-enumerator,
- unordered-containers >= 0.1.4 && < 0.1.5
- ghc-options: -Wall -fno-warn-unused-do-bind -O2
-
-Executable simpleclient
- hs-source-dirs: src
- Main-is: SimpleClient.hs
- Build-depends: base >= 4.2 && < 5,
- bytestring,
- unordered-containers,
- enumerator,
- text,
- transformers,
- aeson >= 0.4 && < 0.5,
- attoparsec-enumerator,
- http-types,
- wai,
- warp
- ghc-options: -Wall -fno-warn-unused-do-bind -O2
View
39 src/SimpleClient.hs
@@ -1,39 +0,0 @@
-{-# LANGUAGE OverloadedStrings #-}
-module Main where
-
-import Network.HTTP.Enumerator
- ( http, parseUrl, withManager, RequestBody (RequestBodyLBS)
- , requestBody
- )
-import Data.Aeson (Value (Object, String))
-import qualified Data.HashMap.Lazy as Map
-import Data.Aeson.Parser (json)
-import Data.Attoparsec.Enumerator (iterParser)
-import Control.Monad.IO.Class (liftIO)
-import Data.Enumerator (run_)
-import Data.Aeson.Encode (fromValue)
-import Blaze.ByteString.Builder (toLazyByteString)
-
-main :: IO ()
-main = withManager $ \manager -> do
- value <- makeValue
- -- We need to know the size of the request body, so we convert to a
- -- ByteString
- let valueBS = toLazyByteString $ fromValue value
- req' <- parseUrl "http://localhost:3000/"
- let req = req' { requestBody = RequestBodyLBS valueBS }
- run_ $ flip (http req) manager $ \status headers -> do
- -- Might want to ensure we have a 200 status code and Content-Type is
- -- application/json. We skip that here.
- resValue <- iterParser json
- liftIO $ handleResponse resValue
-
--- Application-specific function to make the request value
-makeValue :: IO Value
-makeValue = return $ Object $ Map.fromList
- [ ("foo", String "bar")
- ]
-
--- Application-specific function to handle the response from the server
-handleResponse :: Value -> IO ()
-handleResponse = print
View
41 src/SpiritService.hs
@@ -1,41 +0,0 @@
-{-# LANGUAGE OverloadedStrings #-}
-
-module Main where
-
-import Network.Wai (Response (ResponseBuilder), Application)
-import Network.HTTP.Types (status200, status400)
-import Network.Wai.Handler.Warp (run)
-import Data.Aeson.Parser (json)
-import Data.Attoparsec.Enumerator (iterParser)
-import Control.Monad.IO.Class (liftIO)
-import Data.Aeson (Value (Object, String))
-import Data.Aeson.Encode (fromValue)
-import Data.Enumerator (catchError, Iteratee)
-import Control.Exception (SomeException)
-import Data.ByteString (ByteString)
-import qualified Data.HashMap.Lazy as Map
-import Data.Text (pack)
-
-main :: IO ()
-main = run 3000 app
-
-app :: Application
-app _ = flip catchError invalidJson $ do
- value <- iterParser json
- newValue <- liftIO $ modValue value
- return $ ResponseBuilder
- status200
- [("Content-Type", "application/json")]
- $ fromValue newValue
-
-invalidJson :: SomeException -> Iteratee ByteString IO Response
-invalidJson ex = return $ ResponseBuilder
- status400
- [("Content-Type", "application/json")]
- $ fromValue $ Object $ Map.fromList
- [ ("message", String $ pack $ show ex)
- ]
-
--- Application-specific logic would go here.
-modValue :: Value -> IO Value
-modValue = return
Please sign in to comment.
Something went wrong with that request. Please try again.