yesod-form-json-0.0.1: Extension for Yesod web framework to handle JSON requests as applicative forms

Safe HaskellNone

Yesod.Form.JSON

Contents

Synopsis

The example of use

 data Offer = Offer {
      name :: Text
    , description Text
    , supplier :: SupplierId
    , category :: CategoryId
    , tags :: [TagId] 
    , images :: [Image]
    , variants :: [Variant]
    , active :: Bool
 }
 offer <- runJSONForm $ Offer <$> ireq textField "name"
                              <*> ireq textField "description"
                              <*> ireq jsonField "supplier" 
                              <*> ireq jsonField "category")
                              <*> ireq jsonField "tags")
                              <*> ireq jsonField "images"
                              <*> (fmap nub $ ireq jsonField "variants")
                              <*> ireq boolField "active"     

Functions

runJSONForm :: MonadHandler m => FormInput m a -> m aSource

Run JSON form

jsonField :: (Monad m, FromJSON a) => RenderMessage (HandlerSite m) FormMessage => Field m aSource

Obtain JSON field from json request