git.iko.soy/typeable/http-api-data
on master help sign in
Add functions to parse bounded data based on ToHttpApiData instance
commitcf58f9926b9170da1f35df0c7d45c2e6a2139021 authorCatherine Galkina <catherine@getshoptv.com> dateWed 8 Jun 2016, 17:15 (10 years ago) parent028550b
1 file changed+15
Web/HttpApiData/Internal.hs+15
Web/HttpApiData/Internal.hs+15
@@ -284,6 +284,21 @@ parseBoundedTextData = parseMaybeTextData (flip lookup values . T.toLower)
284284 where
285285 values = map (showTextData &&& id) [minBound..maxBound]
286286
287+parseBoundedUrlPiece :: (ToHttpApiData a, Bounded a, Enum a) => Text -> Either Text a
288+parseBoundedUrlPiece = parseMaybeTextData (flip lookup values . T.toLower)
289+ where
290+ values = map (toUrlPiece &&& id) [minBound..maxBound]
291+
292+parseBoundedQueryParam :: (ToHttpApiData a, Bounded a, Enum a) => Text -> Either Text a
293+parseBoundedQueryParam = parseMaybeTextData (flip lookup values . T.toLower)
294+ where
295+ values = map (toQueryParam &&& id) [minBound..maxBound]
296+
297+parseBoundedHeader :: (ToHttpApiData a, Bounded a, Enum a) => Text -> Either Text a
298+parseBoundedHeader = parseMaybeTextData (flip lookup values . T.toLower)
299+ where
300+ values = map (decodeUtf8 . toHeader &&& id) [minBound..maxBound]
301+
287302-- | Parse URL piece using @'Read'@ instance.
288303--
289304-- Use for types which do not involve letters: