git.iko.soy/typeable/http-api-data
on master help sign in
Add default signature for PathPiece to use To/FromHttpApiData
f440e7aNickolay Kudasov
Web/PathPieces.hs+10−3
@@ -1,4 +1,4 @@
1−{-# LANGUAGE FlexibleInstances, TypeSynonymInstances, OverloadedStrings #-}
1+{-# LANGUAGE FlexibleInstances, TypeSynonymInstances, OverloadedStrings, DefaultSignatures #-}
2module Web.PathPieces
2module Web.PathPieces
3 ( PathPiece (..)
3 ( PathPiece (..)
4 , PathMultiPiece (..)
4 , PathMultiPiece (..)
@@ -15,9 +15,16 @@ import Data.Time (Day)
15import Control.Exception (assert)
15import Control.Exception (assert)
16import Text.Read (readMaybe)
16import Text.Read (readMaybe)
17
17
18+import Web.HttpApiData
19+
18class PathPiece s where
20class PathPiece s where
21+ fromPathPiece :: S.Text -> Maybe s
19− fromPathPiece :: S.Text -> Maybe s
22+ default fromPathPiece :: FromHttpApiData s => S.Text -> Maybe s
23+ fromPathPiece = either (const Nothing) Just . parseUrlPiece
24+
20− toPathPiece :: s -> S.Text
25+ toPathPiece :: s -> S.Text
26+ default toPathPiece :: ToHttpApiData s => s -> S.Text
27+ toPathPiece = toUrlPiece
21
28
22instance PathPiece () where
29instance PathPiece () where
23 fromPathPiece t = if t == "_" then Just () else Nothing
30 fromPathPiece t = if t == "_" then Just () else Nothing