{-# LANGUAGE OverloadedStrings #-}
import Network.Wai
import Network.HTTP.Types (status200)
import Network.Wai.Handler.Warp (run)
application _ = return $
responseLBS status200 [("Content-Type", "text/plain")] "Hello World"
main = run 3000 application
{-# LANGUAGE OverloadedStrings #-}
import Network.Wai
import Network.Wai.Handler.Warp (run)
import Network.Wai.Middleware.Gzip (gzip, def)
import Network.HTTP.Types (status200)
application _ = return $
responseLBS status200 [("Content-Type", "text/plain")] "Hello World"
main = run 3000 $ gzip def application
app req = return $ case pathInfo req of ["yay"] -> yay -- url-bestandteile ohne query-string x -> index x -- evtl. 404
yay = ResponseBuilder status200 ...
index x = ResponseBuilder status200 ...
...
server { listen 80; server_name www.myserver.com; location / { proxy_pass http://127.0.0.1:3000; } }
...
/ HomeR METHOD
/route RouteR METHOD METHOD
/route/#routeVar RouteVarR METHOD
/route/*routeVars RouteVarsR METHOD
/static StaticR Static getStatic
/route RouteR METHOD ...
-- wird zu
methodRoute :: Handler Html
-- route
/route RouteR GET
-- handler
getRoute :: Handler -> Html
-- route
/route RouteR POST
-- handler
postRoute :: Handler -> Text
-- route
/route RouteR
-- handler
handleRoute :: Handler -> Html
-- route
/route/#URLType RouteR METHOD
-- PathPiece methods
instance PathPiece URLType where
toPathPiece (URLType t) = toPathPiece t
fromPathPiece p = do
t <- fromPathPiece p
return $ URLType t
fromPathPiece _ = Nothing -- nicht immer erforderlich, evtl. 404?
instance PathPiece Bool where
toPathPiece b = toPathPiece (if b then 1 else 0 :: Int)
fromPathPiece p = do
x <- fromPathPiece p
case x :: Int of
0 -> return False
1 -> return True
_ -> Nothing
-- route
/route/*URLType RouteR METHOD
-- PathMultiPiece methods
instance PathMultiPiece URLType where
toPathMultiPiece (URLType t1 t2) = [toPathPiece t1, toPathPiece t2]
fromPathMultiPiece [p1,p2] = do
t1 <- fromPathPiece p1
t2 <- fromPathPiece p2
return $ URLType t1 t2
fromPathMultiPiece _ = Nothing -- evtl. 404?
data Natural = Natural Integer deriving (Eq, Show, Read)
data Binary = Binary String deriving (Eq, Show, Read)
toBinary :: Natural -> Binary
toBinary n = Binary $ getBinary $ fromNatural n where
getBinary i = showIntAtBase 2 intToDigit i ""
fromBinary :: Binary -> String
fromBinary (Binary b) = b
toNatural :: Binary -> Natural
toNatural b = Natural $ bin2dec $ fromBinary b where
bin2dec = foldr (\c s -> s * 2 + c) 0 . reverse . map c2i where
c2i '0' = 0
c2i '1' = 1
c2i _ = error "no binary"
fromNatural :: Natural -> Integer
fromNatural (Natural n) = n