digestive-functors-scotty-0.2.0.1: Scotty backend for the digestive-functors library

Safe HaskellNone

Text.Digestive.Scotty

Description

Module providing the scotty backend for the digestive-functors library


import Web.Scotty

import Text.Digestive
import Text.Digestive.Scotty

import Control.Applicative ((<$>), (<*>))

data FormData = FormData { field1 :: String
                         , field2 :: Integer
                         }

testForm :: Monad m => Form String m FormData
testForm = FormData
           <$> "field1" .: string Nothing
           <*> "field2" .: stringRead "read failed" Nothing

main :: IO ()
main = scotty 3000 $ do
    get "/" $ do
        setHeader "Content-Type" "text/html"
        raw " <html><body><form enctype='multipart/form-data' method='post'> \
              \ <input type='text' name='test-form.field1'/> \
              \ <input type='text' name='test-form.field2'/> \
              \ <input type='submit'/> \
              \ </form></body></html>"

    post "/" $ do
        (view, result) <- runForm "test-form" testForm
        case result of
            Just d -> ... Success! `d` contains constructed FormData.
            _ -> ... Failure! Use `view` variable to access error messages.

Synopsis

Documentation

runFormSource

Arguments

:: (Monad m, ScottyError e) 
=> Text

Name of the form

-> Form v (ActionT e m) a

Form to run

-> ActionT e m (View v, Maybe a)

Result

Runs a form with the HTTP input provided by Scotty.