Skip to content

Commit

Permalink
Add haddock
Browse files Browse the repository at this point in the history
  • Loading branch information
jtanguy committed Sep 4, 2015
1 parent 77efcbf commit 68aca66
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
18 changes: 14 additions & 4 deletions QuickWebApp.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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 <http://localhost:8080> or by using
curl/httpie
> http :8080 input="<your input string>"
> curl localhost:8080 -d input="<your input string>"
-}
interactWeb :: (FromText a, ToText b) => (a -> Either String b) -> IO ()
interactWeb f = do
port <- maybe 8080 read <$> lookupEnv "PORT"
Expand Down
2 changes: 1 addition & 1 deletion default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions quickwebapp.cabal
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
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
'Prelude'.
.
> 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
Expand Down

0 comments on commit 68aca66

Please sign in to comment.