git.iko.soy/typeable/http-api-data
on master help sign in
Rename encode/decodeWith*From to encode/decodeAsForm
236c59aNickolay Kudasov
src/Web/HttpApiData.hs+4−1
@@ -37,7 +37,10 @@ module Web.HttpApiData (
37 parseBoundedEnumOfI,
37 parseBoundedEnumOfI,
38 parseBoundedTextData,
38 parseBoundedTextData,
39
39
40− -- * Encoding and decoding forms,
40+ -- * Encoding and decoding @'Form'@s
41+ encodeAsForm,
42+ decodeAsForm,
43+
41 encodeForm,
44 encodeForm,
42 decodeForm,
45 decodeForm,
43
46
src/Web/HttpApiData/Internal/FormUrlEncoded.hs+8−8
@@ -316,22 +316,22 @@ data Proxy3 a b c = Proxy3
316
316
317-- | This is a convenience function for decoding a
317-- | This is a convenience function for decoding a
318-- @application/x-www-form-urlencoded@ 'BSL.ByteString' directly to a datatype
318-- @application/x-www-form-urlencoded@ 'BSL.ByteString' directly to a datatype
319−-- that has an instance for 'FromForm'.
319+-- that has an instance of 'FromForm'.
320--
320--
321-- This is effectively @'fromForm' '<=<' 'decodeForm'@.
321-- This is effectively @'fromForm' '<=<' 'decodeForm'@.
322--
322--
323−-- >>> decodeWithFromForm "name=Dennis&age=22" :: Either T.Text Person
323+-- >>> decodeAsForm "name=Dennis&age=22" :: Either T.Text Person
324-- Right (Person {name = "Dennis", age = 22})
324-- Right (Person {name = "Dennis", age = 22})
325−decodeWithFromForm :: FromForm a => BSL.ByteString -> Either T.Text a
325+decodeAsForm :: FromForm a => BSL.ByteString -> Either T.Text a
326−decodeWithFromForm = fromForm <=< decodeForm
326+decodeAsForm = fromForm <=< decodeForm
327
327
328-- | This is a convenience function for encoding a datatype that has instance
328-- | This is a convenience function for encoding a datatype that has instance
329−-- for 'ToForm' directly to a @application/x-www-form-urlencoded@
329+-- of 'ToForm' directly to a @application/x-www-form-urlencoded@
330-- 'BSL.ByteString'.
330-- 'BSL.ByteString'.
331--
331--
332-- This is effectively @'encodeForm' . 'toForm'@.
332-- This is effectively @'encodeForm' . 'toForm'@.
333--
333--
334−-- >>> encodeWithToForm Person {name = "Dennis", age = 22}
334+-- >>> encodeAsForm Person {name = "Dennis", age = 22}
335-- "age=22&name=Dennis"
335-- "age=22&name=Dennis"
336−encodeWithToForm :: ToForm a => a -> BSL.ByteString
336+encodeAsForm :: ToForm a => a -> BSL.ByteString
337−encodeWithToForm = encodeForm . toForm
337+encodeAsForm = encodeForm . toForm
test/Web/HttpApiData/Internal/FormUrlEncodedSpec.hs+4−4
@@ -77,8 +77,8 @@ urlEncoding = describe "urlEncoding" $ do
77 it "decodeForm (encodeForm x) == Right x" $ property $ \(NoEmptyKeyForm x) -> do
77 it "decodeForm (encodeForm x) == Right x" $ property $ \(NoEmptyKeyForm x) -> do
78 decodeForm (encodeForm x) `shouldBe` Right x
78 decodeForm (encodeForm x) `shouldBe` Right x
79
79
80− it "decodeWithFromForm == (fromForm <=< decodeForm)" $ property $ \(x :: BSL.ByteString) -> do
80+ it "decodeAsForm == (fromForm <=< decodeForm)" $ property $ \(x :: BSL.ByteString) -> do
81− (decodeWithFromForm x :: Either Text Form) `shouldBe` (fromForm <=< decodeForm) x
81+ (decodeAsForm x :: Either Text Form) `shouldBe` (fromForm <=< decodeForm) x
82
82
83− it "encodeWithToForm == encodeForm . toForm" $ property $ \(x :: Form) -> do
83+ it "encodeAsForm == encodeForm . toForm" $ property $ \(x :: Form) -> do
84− encodeWithToForm x `shouldBe` (encodeForm . toForm) x
84+ encodeAsForm x `shouldBe` (encodeForm . toForm) x