git.iko.soy/typeable/http-api-data
on master help sign in
Rename encode/decodeWith*From to encode/decodeAsForm
commit236c59a62ba59c3eea7ad54ea8cd67847a375222 authorNickolay Kudasov <nickolay.kudasov@gmail.com> dateMon 29 Aug 2016, 14:48 (10 years ago) parent6ab8a56
3 files changed+16−13
src/Web/HttpApiData.hs+4−1 src/Web/HttpApiData/Internal/FormUrlEncoded.hs+8−8 test/Web/HttpApiData/Internal/FormUrlEncodedSpec.hs+4−4
src/Web/HttpApiData.hs+4−1
@@ -37,7 +37,10 @@ module Web.HttpApiData (
3737 parseBoundedEnumOfI,
3838 parseBoundedTextData,
3939
40− -- * Encoding and decoding forms,
40+ -- * Encoding and decoding @'Form'@s
41+ encodeAsForm,
42+ decodeAsForm,
43+
4144 encodeForm,
4245 decodeForm,
4346
src/Web/HttpApiData/Internal/FormUrlEncoded.hs+8−8
@@ -316,22 +316,22 @@ data Proxy3 a b c = Proxy3
316316
317317-- | This is a convenience function for decoding a
318318-- @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'.
320320--
321321-- This is effectively @'fromForm' '<=<' 'decodeForm'@.
322322--
323−-- >>> decodeWithFromForm "name=Dennis&age=22" :: Either T.Text Person
323+-- >>> decodeAsForm "name=Dennis&age=22" :: Either T.Text Person
324324-- Right (Person {name = "Dennis", age = 22})
325−decodeWithFromForm :: FromForm a => BSL.ByteString -> Either T.Text a
326−decodeWithFromForm = fromForm <=< decodeForm
325+decodeAsForm :: FromForm a => BSL.ByteString -> Either T.Text a
326+decodeAsForm = fromForm <=< decodeForm
327327
328328-- | 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@
330330-- 'BSL.ByteString'.
331331--
332332-- This is effectively @'encodeForm' . 'toForm'@.
333333--
334−-- >>> encodeWithToForm Person {name = "Dennis", age = 22}
334+-- >>> encodeAsForm Person {name = "Dennis", age = 22}
335335-- "age=22&name=Dennis"
336−encodeWithToForm :: ToForm a => a -> BSL.ByteString
337−encodeWithToForm = encodeForm . toForm
336+encodeAsForm :: ToForm a => a -> BSL.ByteString
337+encodeAsForm = encodeForm . toForm
test/Web/HttpApiData/Internal/FormUrlEncodedSpec.hs+4−4
@@ -77,8 +77,8 @@ urlEncoding = describe "urlEncoding" $ do
7777 it "decodeForm (encodeForm x) == Right x" $ property $ \(NoEmptyKeyForm x) -> do
7878 decodeForm (encodeForm x) `shouldBe` Right x
7979
80− it "decodeWithFromForm == (fromForm <=< decodeForm)" $ property $ \(x :: BSL.ByteString) -> do
81− (decodeWithFromForm x :: Either Text Form) `shouldBe` (fromForm <=< decodeForm) x
80+ it "decodeAsForm == (fromForm <=< decodeForm)" $ property $ \(x :: BSL.ByteString) -> do
81+ (decodeAsForm x :: Either Text Form) `shouldBe` (fromForm <=< decodeForm) x
8282
83− it "encodeWithToForm == encodeForm . toForm" $ property $ \(x :: Form) -> do
84− encodeWithToForm x `shouldBe` (encodeForm . toForm) x
83+ it "encodeAsForm == encodeForm . toForm" $ property $ \(x :: Form) -> do
84+ encodeAsForm x `shouldBe` (encodeForm . toForm) x