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.
-
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" fInstead 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 PersonThe default implementation of fromForm is genericFromForm. It only works for records and it will use parseQueryParam for each field's value. -
http-api-data Web.FormUrlEncoded Typeclass for types that can be parsed from keys of a Form. This is the reverse of ToFormKey.
-
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 PersonThe default implementation of toForm is genericToForm. -
http-api-data Web.FormUrlEncoded Typeclass for types that can be used as keys in a Form-like container (like Map).
defaultFormOptions :: FormOptionshttp-api-data Web.FormUrlEncoded Default encoding FormOptions.
FormOptions { fieldLabelModifier = id }
fromForm :: FromForm a => Form -> Either Text ahttp-api-data Web.FormUrlEncoded Parse Form into a value.
genericFromForm :: (Generic a, GFromForm a (Rep a)) => FormOptions -> Form -> Either Text ahttp-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;
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"]})genericToForm :: (Generic a, GToForm a (Rep a)) => FormOptions -> a -> Formhttp-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;
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"parseFormKey :: FromFormKey k => Text -> Either Text khttp-api-data Web.FormUrlEncoded Parse a key of a Form.
toForm :: ToForm a => a -> Formhttp-api-data Web.FormUrlEncoded Convert a value into Form.