@@ -36,7 +36,7 @@ where
36import Data.Proxy (Proxy (Proxy))
36import Data.Proxy (Proxy (Proxy))
37import GHC.TypeLits (Nat)
37import GHC.TypeLits (Nat)
38import Network.HTTP.Types (Status, StdMethod)
38import Network.HTTP.Types (Status, StdMethod)
39−import Servant.API.ContentTypes (NoContent, MimeRender(mimeRender), MimeUnrender(mimeUnrender))
39+import Servant.API.ContentTypes (JSON, PlainText, FormUrlEncoded, OctetStream, NoContent, MimeRender(mimeRender), MimeUnrender(mimeUnrender))
40import Servant.API.Status (KnownStatus, statusVal)
40import Servant.API.Status (KnownStatus, statusVal)
41import Servant.API.UVerb.Union
41import Servant.API.UVerb.Union
@@ -69,13 +69,6 @@ instance (HasStatus a, HasStatuses as) => HasStatuses (a ': as) where
69newtype WithStatus (k :: Nat) a = WithStatus a
69newtype WithStatus (k :: Nat) a = WithStatus a
70 deriving (Eq, Show)
70 deriving (Eq, Show)
72−instance MimeRender ctype a => MimeRender ctype (WithStatus _status a) where
73− mimeRender contentTypeProxy (WithStatus a) = mimeRender contentTypeProxy a
75−instance MimeUnrender ctype a => MimeUnrender ctype (WithStatus _status a) where
76− mimeUnrender contentTypeProxy input =
77− WithStatus <$> mimeUnrender contentTypeProxy input
79-- | an instance of this typeclass assigns a HTTP status code to a return type
72-- | an instance of this typeclass assigns a HTTP status code to a return type
81-- Example:
74-- Example:
@@ -105,3 +98,27 @@ instance KnownStatus n => HasStatus (WithStatus n a) where
105-- Backwards compatibility is tricky, though: this type alias would mean people would have to
98-- Backwards compatibility is tricky, though: this type alias would mean people would have to
106-- use 'respond' instead of 'pure' or 'return', so all old handlers would have to be rewritten.
99-- use 'respond' instead of 'pure' or 'return', so all old handlers would have to be rewritten.
107data UVerb (method :: StdMethod) (contentTypes :: [*]) (as :: [*])
100data UVerb (method :: StdMethod) (contentTypes :: [*]) (as :: [*])
102+instance {-# OVERLAPPING #-} MimeRender JSON a => MimeRender JSON (WithStatus _status a) where
103+ mimeRender contentTypeProxy (WithStatus a) = mimeRender contentTypeProxy a
105+instance {-# OVERLAPPING #-} MimeRender PlainText a => MimeRender PlainText (WithStatus _status a) where
106+ mimeRender contentTypeProxy (WithStatus a) = mimeRender contentTypeProxy a
108+instance {-# OVERLAPPING #-} MimeRender FormUrlEncoded a => MimeRender FormUrlEncoded (WithStatus _status a) where
109+ mimeRender contentTypeProxy (WithStatus a) = mimeRender contentTypeProxy a
111+instance {-# OVERLAPPING #-} MimeRender OctetStream a => MimeRender OctetStream (WithStatus _status a) where
112+ mimeRender contentTypeProxy (WithStatus a) = mimeRender contentTypeProxy a
114+instance {-# OVERLAPPING #-} MimeUnrender JSON a => MimeUnrender JSON (WithStatus _status a) where
115+ mimeUnrender contentTypeProxy input = WithStatus <$> mimeUnrender contentTypeProxy input
117+instance {-# OVERLAPPING #-} MimeUnrender PlainText a => MimeUnrender PlainText (WithStatus _status a) where
118+ mimeUnrender contentTypeProxy input = WithStatus <$> mimeUnrender contentTypeProxy input
120+instance {-# OVERLAPPING #-} MimeUnrender FormUrlEncoded a => MimeUnrender FormUrlEncoded (WithStatus _status a) where
121+ mimeUnrender contentTypeProxy input = WithStatus <$> mimeUnrender contentTypeProxy input
123+instance {-# OVERLAPPING #-} MimeUnrender OctetStream a => MimeUnrender OctetStream (WithStatus _status a) where
124+ mimeUnrender contentTypeProxy input = WithStatus <$> mimeUnrender contentTypeProxy input