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.

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

    http-api-data Web.FormUrlEncoded

    Parse Form into a value.

  2. 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"]})
    

  3. 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"
    

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

    http-api-data Web.FormUrlEncoded

    Parse a key of a Form.

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

    http-api-data Web.FormUrlEncoded

    Convert a value into Form.

  6. toFormKey :: ToFormKey k => k -> Text

    http-api-data Web.FormUrlEncoded

    Render a key for a Form.

  7. unForm :: Form -> HashMap Text [Text]

    http-api-data Web.FormUrlEncoded

    No documentation available.

  8. urlDecodeAsForm :: FromForm a => ByteString -> Either Text a

    http-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})
    

  9. urlDecodeForm :: ByteString -> Either Text Form

    http-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"
    

  10. urlEncodeAsForm :: ToForm a => a -> ByteString

    http-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.

Page 500 of many | Previous | Next