diff --git a/servant/src/Servant/API/ContentTypes.hs b/servant/src/Servant/API/ContentTypes.hs index 1bb955162..3c9e6d5bd 100644 --- a/servant/src/Servant/API/ContentTypes.hs +++ b/servant/src/Servant/API/ContentTypes.hs @@ -158,16 +158,19 @@ newtype AcceptHeader = AcceptHeader BS.ByteString -- Example: -- -- > data MyContentType +-- > newtype MyData = MyData String -- > -- > instance Accept MyContentType where -- > contentType _ = "example" // "prs.me.mine" /: ("charset", "utf-8") -- > --- > instance Show a => MimeRender MyContentType a where --- > mimeRender _ val = pack ("This is MINE! " ++ show val) +-- > instance MimeRender MyContentType MyData where +-- > mimeRender _ (MyData val) = pack ("This is MINE! " ++ val) -- > -- > type MyAPI = "path" :> Get '[MyContentType] Int class Accept ctype => MimeRender ctype a where - mimeRender :: Proxy ctype -> a -> ByteString + type MimeRenderType a :: Type + type MimeRenderType a = ByteString + mimeRender :: Proxy ctype -> a -> MimeRenderType a class AllMime list => AllCTRender (list :: [Type]) a where -- If the Accept header can be matched, returns (Just) a tuple of the @@ -197,7 +200,8 @@ instance -- -- >>> import Network.HTTP.Media hiding (Accept) -- >>> import qualified Data.ByteString.Lazy.Char8 as BSC --- >>> data MyContentType = MyContentType String +-- >>> data MyContentType +-- >>> newtype MyData = MyData String -- -- >>> :{ -- instance Accept MyContentType where @@ -205,15 +209,17 @@ instance -- :} -- -- >>> :{ --- instance Read a => MimeUnrender MyContentType a where +-- instance MimeUnrender MyContentType MyData where -- mimeUnrender _ bs = case BSC.take 12 bs of --- "MyContentType" -> return . read . BSC.unpack $ BSC.drop 12 bs +-- "MyContentType" -> return . MyData . BSC.unpack $ BSC.drop 12 bs -- _ -> Left "didn't start with the magic incantation" -- :} -- -- >>> type MyAPI = "path" :> ReqBody '[MyContentType] Int :> Get '[JSON] Int class Accept ctype => MimeUnrender ctype a where - mimeUnrender :: Proxy ctype -> ByteString -> Either String a + type MimeUnrenderType a :: Type + type MimeUnrenderType a = ByteString + mimeUnrender :: Proxy ctype -> MimeUnrenderType a -> Either String a mimeUnrender p = mimeUnrenderWithType p (contentType p) -- | Variant which is given the actual 'M.MediaType' provided by the other party.