Hoogle Search

Within LTS Haskell 24.39 (ghc-9.10.3)

Note that Stackage only displays results for the latest LTS and Nightly snapshot. Learn more.

  1. class FromForm a

    http-api-data Web.FormUrlEncoded

    Parse Form into a value. An example type and instance:

    data Person = Person
    { name :: String
    , age  :: Int }
    
    instance FromForm Person where
    fromForm f = Person
    <$> parseUnique "name" f
    <*> parseUnique "age"  f
    
    Instead of manually writing FromForm instances you can use a default generic implementation of fromForm. To do that, simply add deriving Generic clause to your datatype and declare a FromForm instance for your datatype without giving definition for fromForm. For instance, the previous example can be simplified into this:
    data Person = Person
    { name :: String
    , age  :: Int
    } deriving (Generic)
    
    instance FromForm Person
    
    The default implementation of fromForm is genericFromForm. It only works for records and it will use parseQueryParam for each field's value.

  2. class FromFormKey k

    http-api-data Web.FormUrlEncoded

    Typeclass for types that can be parsed from keys of a Form. This is the reverse of ToFormKey.

  3. class ToForm a

    http-api-data Web.FormUrlEncoded

    Convert a value into Form. An example type and instance:

    {-# LANGUAGE OverloadedLists #-}
    
    data Person = Person
    { name :: String
    , age  :: Int }
    
    instance ToForm Person where
    toForm person =
    [ ("name", toQueryParam (name person))
    , ("age", toQueryParam (age person)) ]
    
    Instead of manually writing ToForm instances you can use a default generic implementation of toForm. To do that, simply add deriving Generic clause to your datatype and declare a ToForm instance for your datatype without giving definition for toForm. For instance, the previous example can be simplified into this:
    data Person = Person
    { name :: String
    , age  :: Int
    } deriving (Generic)
    
    instance ToForm Person
    
    The default implementation of toForm is genericToForm.

  4. class ToFormKey k

    http-api-data Web.FormUrlEncoded

    Typeclass for types that can be used as keys in a Form-like container (like Map).

  5. defaultFormOptions :: FormOptions

    http-api-data Web.FormUrlEncoded

    Default encoding FormOptions.

    FormOptions
    { fieldLabelModifier = id
    }
    

  6. fromForm :: FromForm a => Form -> Either Text a

    http-api-data Web.FormUrlEncoded

    Parse Form into a value.

  7. genericFromForm :: (Generic a, GFromForm a (Rep a)) => FormOptions -> Form -> Either Text a

    http-api-data Web.FormUrlEncoded

    A Generic-based implementation of fromForm. This is used as a default implementation in FromForm. Note that this only works for records (i.e. product data types with named fields):

    data Person = Person
    { name :: String
    , age  :: Int
    } deriving (Generic)
    
    In this implementation each field's value gets decoded using parseQueryParam. Two field types are exceptions:
    • for values of type Maybe a an entry is parsed if present in the Form and the is decoded with parseQueryParam; if no entry is present result is Nothing;
    • for values of type [a] (except [Char]) all entries are parsed to produce a list of parsed values;
    Here's an example:
    data Post = Post
    { title    :: String
    , subtitle :: Maybe String
    , comments :: [String]
    } deriving (Generic, Show)
    
    instance FromForm Post
    
    >>> urlDecodeAsForm "comments=Nice%20post%21&comments=%2B1&title=Test" :: Either Text Post
    Right (Post {title = "Test", subtitle = Nothing, comments = ["Nice post!","+1"]})
    

  8. genericToForm :: (Generic a, GToForm a (Rep a)) => FormOptions -> a -> Form

    http-api-data Web.FormUrlEncoded

    A Generic-based implementation of toForm. This is used as a default implementation in ToForm. Note that this only works for records (i.e. product data types with named fields):

    data Person = Person
    { name :: String
    , age  :: Int
    } deriving (Generic)
    
    In this implementation each field's value gets encoded using toQueryParam. Two field types are exceptions:
    • for values of type Maybe a an entry is added to the Form only when it is Just x and the encoded value is toQueryParam x; Nothing values are omitted from the Form;
    • for values of type [a] (except [Char]) an entry is added for every item in the list; if the list is empty no entries are added to the Form;
    Here's an example:
    data Post = Post
    { title    :: String
    , subtitle :: Maybe String
    , comments :: [String]
    } deriving (Generic, Show)
    
    instance ToForm Post
    
    >>> urlEncodeAsFormStable Post { title = "Test", subtitle = Nothing, comments = ["Nice post!", "+1"] }
    "comments=Nice%20post%21&comments=%2B1&title=Test"
    

  9. parseFormKey :: FromFormKey k => Text -> Either Text k

    http-api-data Web.FormUrlEncoded

    Parse a key of a Form.

  10. toForm :: ToForm a => a -> Form

    http-api-data Web.FormUrlEncoded

    Convert a value into Form.

Page 500 of many | Previous | Next