@@ -1,4 +1,4 @@
1−{-# LANGUAGE FlexibleInstances, TypeSynonymInstances, OverloadedStrings #-}
1+{-# LANGUAGE FlexibleInstances, TypeSynonymInstances, OverloadedStrings, DefaultSignatures #-}
22module Web.PathPieces
33 ( PathPiece (..)
44 , PathMultiPiece (..)
@@ -15,9 +15,16 @@ import Data.Time (Day)
1515import Control.Exception (assert)
1616import Text.Read (readMaybe)
1717
18+import Web.HttpApiData
19+
1820class PathPiece s where
19− fromPathPiece :: S.Text -> Maybe s
20− toPathPiece :: s -> S.Text
21+ fromPathPiece :: S.Text -> Maybe s
22+ default fromPathPiece :: FromHttpApiData s => S.Text -> Maybe s
23+ fromPathPiece = either (const Nothing) Just . parseUrlPiece
24+
25+ toPathPiece :: s -> S.Text
26+ default toPathPiece :: ToHttpApiData s => s -> S.Text
27+ toPathPiece = toUrlPiece
2128
2229instance PathPiece () where
2330 fromPathPiece t = if t == "_" then Just () else Nothing