From 68aca6630ba214b39643ed35ae7dc98e40efa694 Mon Sep 17 00:00:00 2001 From: Julien Tanguy Date: Fri, 4 Sep 2015 17:52:41 +0200 Subject: [PATCH] Add haddock --- QuickWebApp.hs | 18 ++++++++++++++---- default.nix | 2 +- quickwebapp.cabal | 4 ++-- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/QuickWebApp.hs b/QuickWebApp.hs index 9735c38..a17b48b 100644 --- a/QuickWebApp.hs +++ b/QuickWebApp.hs @@ -4,9 +4,9 @@ {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE TypeOperators #-} -{-| A quick-and-dirty api generator, for any function `a -> b` which can be wrapped - inside a function `ByteString -> ByteString`. - It is inspired from the 'interact' function from 'Prelude'. +{-| A quick-and-dirty api generator, for any function @a -> "Either" "String" b@. + +If you only have a function @f :: a -> b@, simply run @interactWeb ("Right" .f)@ -} module QuickWebApp ( interactWeb @@ -23,7 +23,7 @@ import GHC.Generics import Network.Wai.Handler.Warp import System.Environment -import Lucid +import Lucid import Servant import Servant.HTML.Lucid @@ -85,6 +85,16 @@ instance FromFormUrlEncoded Input where newtype Output = Output { output :: Text } deriving (Show, Eq, Generic) instance ToJSON Output +{-| Tranform a function into a webapp. +The inputs and outputs must implement 'FromText' and 'ToText', respectively. + +You can query it via a browser at or by using +curl/httpie + + > http :8080 input="" + + > curl localhost:8080 -d input="" +-} interactWeb :: (FromText a, ToText b) => (a -> Either String b) -> IO () interactWeb f = do port <- maybe 8080 read <$> lookupEnv "PORT" diff --git a/default.nix b/default.nix index 083339f..4db33cc 100644 --- a/default.nix +++ b/default.nix @@ -3,7 +3,7 @@ }: mkDerivation { pname = "quickwebapp"; - version = "3.0.0.0"; + version = "3.0.0.1"; src = ./.; libraryHaskellDepends = [ aeson base bytestring containers either lucid servant servant-lucid diff --git a/quickwebapp.cabal b/quickwebapp.cabal index e5798e5..7815b1d 100644 --- a/quickwebapp.cabal +++ b/quickwebapp.cabal @@ -1,5 +1,5 @@ name: quickwebapp -version: 3.0.0.0 +version: 3.0.0.1 synopsis: A quick webapp generator for any file processing tool description: A quick-and-dirty api generator, inspired from the 'interact' function from @@ -7,7 +7,7 @@ description: . > interactWeb reverse . - This creates a server listening on port 3000. + This creates a server listening on port 8080, or environment value PORT. . license: GPL-3 license-file: LICENSE