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