Hoogle Search
Within LTS Haskell 24.38 (ghc-9.10.3)
Note that Stackage only displays results for the latest LTS and Nightly snapshot. Learn more.
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.
toFormKey :: ToFormKey k => k -> Texthttp-api-data Web.FormUrlEncoded Render a key for a Form.
unForm :: Form -> HashMap Text [Text]http-api-data Web.FormUrlEncoded No documentation available.
urlDecodeAsForm :: FromForm a => ByteString -> Either Text ahttp-api-data Web.FormUrlEncoded This is a convenience function for decoding a application/x-www-form-urlencoded ByteString directly to a datatype that has an instance of FromForm. This is effectively fromForm <=< urlDecodeForm.
>>> urlDecodeAsForm "name=Dennis&age=22" :: Either Text Person Right (Person {name = "Dennis", age = 22})urlDecodeForm :: ByteString -> Either Text Formhttp-api-data Web.FormUrlEncoded Decode an application/x-www-form-urlencoded ByteString to a Form. Key-value pairs get decoded normally:
>>> urlDecodeForm "name=Greg&lastname=Weber" Right (fromList [("lastname","Weber"),("name","Greg")])Keys with no values get decoded to pairs with empty values.>>> urlDecodeForm "is_test" Right (fromList [("is_test","")])Empty keys are allowed:>>> urlDecodeForm "=foobar" Right (fromList [("","foobar")])The empty string gets decoded into an empty Form:>>> urlDecodeForm "" Right (fromList [])
Everything is un-escaped with unEscapeString:>>> urlDecodeForm "fullname=Andres%20L%C3%B6h" Right (fromList [("fullname","Andres L\246h")])Improperly formed strings result in an error:>>> urlDecodeForm "this=has=too=many=equals" Left "not a valid pair: this=has=too=many=equals"
urlEncodeAsForm :: ToForm a => a -> ByteStringhttp-api-data Web.FormUrlEncoded This is a convenience function for encoding a datatype that has instance of ToForm directly to a application/x-www-form-urlencoded ByteString. This is effectively urlEncodeForm . toForm. _NOTE:_ this encoding is unstable and may result in different key order (but not values). For a stable encoding see urlEncodeAsFormStable.