@@ -28,7 +28,6 @@ module Servant.API.UVerb
28 HasStatus (StatusOf),
28 HasStatus (StatusOf),
30 HasStatuses (Statuses, statuses),
30 HasStatuses (Statuses, statuses),
32 module Servant.API.UVerb.Union,
31 module Servant.API.UVerb.Union,
@@ -36,7 +35,7 @@ where
36import Data.Proxy (Proxy (Proxy))
35import Data.Proxy (Proxy (Proxy))
37import GHC.TypeLits (Nat)
36import GHC.TypeLits (Nat)
38import Network.HTTP.Types (Status, StdMethod)
37import Network.HTTP.Types (Status, StdMethod)
39−import Servant.API.ContentTypes (NoContent, MimeRender(mimeRender), MimeUnrender(mimeUnrender))
38+import Servant.API.ContentTypes (MimeRender (mimeRender), MimeUnrender (mimeUnrender), NoContent)
40import Servant.API.Status (KnownStatus, statusVal)
39import Servant.API.Status (KnownStatus, statusVal)
41import Servant.API.UVerb.Union
40import Servant.API.UVerb.Union
@@ -64,36 +63,6 @@ instance (HasStatus a, HasStatuses as) => HasStatuses (a ': as) where
64 type Statuses (a ': as) = StatusOf a ': Statuses as
63 type Statuses (a ': as) = StatusOf a ': Statuses as
65 statuses _ = statusOf (Proxy :: Proxy a) : statuses (Proxy :: Proxy as)
64 statuses _ = statusOf (Proxy :: Proxy a) : statuses (Proxy :: Proxy as)
67−-- | A simple newtype wrapper that pairs a type with its status code. It
68−-- implements all the content types that Servant ships with by default.
69−newtype WithStatus (k :: Nat) a = WithStatus a
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
84−-- data NotFoundError = NotFoundError String
86−-- instance HasStatus NotFoundError where
87−-- type StatusOf NotFoundError = 404
90−-- You can also use the convience newtype wrapper 'WithStatus' if you want to
91−-- avoid writing a 'HasStatus' instance manually. It also has the benefit of
92−-- showing the status code in the type; which might aid in readability.
93−instance KnownStatus n => HasStatus (WithStatus n a) where
94− type StatusOf (WithStatus n a) = n
97-- | A variant of 'Verb' that can have any of a number of response values and status codes.
66-- | A variant of 'Verb' that can have any of a number of response values and status codes.
99-- FUTUREWORK: it would be nice to make 'Verb' a special case of 'UVerb', and only write
68-- FUTUREWORK: it would be nice to make 'Verb' a special case of 'UVerb', and only write