{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
module Servant.API.ContentTypes.Flat where
import Data.Proxy (Proxy(..))
import Network.HTTP.Media ((//))
import qualified Data.List.NonEmpty as NonEmpty
import Servant.API.ContentTypes
import Flat
data FlatFmt
instance Accept FlatFmt where
contentTypes :: Proxy FlatFmt -> NonEmpty MediaType
contentTypes Proxy FlatFmt
Proxy = forall a. [a] -> NonEmpty a
NonEmpty.fromList
[ ByteString
"application" ByteString -> ByteString -> MediaType
// ByteString
"x-hackage-flat"
, ByteString
"application" ByteString -> ByteString -> MediaType
// ByteString
"vnd.hackage.flat"
]
instance Flat a => MimeRender FlatFmt a where
mimeRender :: Proxy FlatFmt -> a -> ByteString
mimeRender Proxy FlatFmt
Proxy = forall a b. (Flat a, AsByteString b) => a -> b
flatRaw
instance Flat a => MimeUnrender FlatFmt a where
mimeUnrender :: Proxy FlatFmt -> ByteString -> Either String a
mimeUnrender Proxy FlatFmt
Proxy = forall {a} {b} {b}. (a -> b) -> Either a b -> Either b b
mapLeft forall {a}. Show a => a -> String
prettyErr forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (Flat a, AsByteString b) => b -> Decoded a
unflatRaw
where
mapLeft :: (a -> b) -> Either a b -> Either b b
mapLeft a -> b
f = forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (forall a b. a -> Either a b
Left forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b
f) forall a b. b -> Either a b
Right
prettyErr :: a -> String
prettyErr a
err = String
"Flat.unflatRaw: " forall a. [a] -> [a] -> [a]
++ forall {a}. Show a => a -> String
show a
err