@@ -13,6 +13,7 @@ module Web.Internal.HttpApiData where
1313import Control.Applicative
1414import Data.Traversable (Traversable(traverse))
1515#endif
16+
1617import Control.Arrow ((&&&), left)
1718import Control.Monad ((<=<))
1819
@@ -35,6 +36,7 @@ import Data.Version
3536
3637#if MIN_VERSION_base(4,8,0)
3738import Data.Void
39+import Numeric.Natural
3840#endif
3941
4042import Text.Read (readMaybe)
@@ -390,8 +392,8 @@ instance ToHttpApiData Version where
390392 toUrlPiece = T.pack . showVersion
391393
392394#if MIN_VERSION_base(4,8,0)
393−instance ToHttpApiData Void where
394− toUrlPiece = absurd
395+instance ToHttpApiData Void where toUrlPiece = absurd
396+instance ToHttpApiData Natural where toUrlPiece = showt
395397#endif
396398
397399instance ToHttpApiData Bool where toUrlPiece = showTextData
@@ -491,6 +493,13 @@ instance FromHttpApiData Version where
491493-- | Parsing a @'Void'@ value is always an error, considering @'Void'@ as a data type with no constructors.
492494instance FromHttpApiData Void where
493495 parseUrlPiece _ = Left "Void cannot be parsed!"
496+
497+instance FromHttpApiData Natural where
498+ parseUrlPiece s = do
499+ n <- runReader (signed decimal) s
500+ if n < 0
501+ then Left ("undeflow: " <> s <> " (should be a non-negative integer)")
502+ else Right (fromInteger n)
494503#endif
495504
496505instance FromHttpApiData Bool where parseUrlPiece = parseBoundedUrlPiece