git.iko.soy/typeable/servant
on master help sign in
Add descriptive type synonyms for success responses.
190c75aJulian K. Arni
servant/src/Servant/API/Verbs.hs+117−11
@@ -20,23 +20,129 @@ import Network.HTTP.Types.Method (Method, StdMethod (..),
20data Verb (method :: k1) (statusCode :: Nat) (contentTypes :: [*]) a
20data Verb (method :: k1) (statusCode :: Nat) (contentTypes :: [*]) a
21 deriving (Typeable, Generic)
21 deriving (Typeable, Generic)
22
22
23−-- 'GET' with 200 status code.
23+-- * 200 responses
24−type Get contentTypes a = Verb 'GET 200 contentTypes a
24+--
25+-- The 200 response is the workhorse of web servers, but also fairly generic.
26+-- When appropriate, you should prefer the more specific success combinators.
27+-- More information about the definitions of status codes can be found in
28+-- <http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html RFC2615> and
29+-- <https://tools.ietf.org/html/rfc7231#section-6 RFC7231 Section 6>;
30+-- the relevant information is summarily presented here.
25
31
32+-- | 'GET' with 200 status code.
33+type Get contentTypes a = Verb 'GET 200 contentTypes a
26−-- 'POST' with 200 status code.
34+-- | 'POST' with 200 status code.
27type Post contentTypes a = Verb 'POST 200 contentTypes a
35type Post contentTypes a = Verb 'POST 200 contentTypes a
28−
29−-- 'PUT' with 200 status code.
36+-- | 'PUT' with 200 status code.
30type Put contentTypes a = Verb 'PUT 200 contentTypes a
37type Put contentTypes a = Verb 'PUT 200 contentTypes a
31−
32−-- 'DELETE' with 200 status code.
38+-- | 'DELETE' with 200 status code.
33type Delete contentTypes a = Verb 'DELETE 200 contentTypes a
39type Delete contentTypes a = Verb 'DELETE 200 contentTypes a
34−
35−-- 'PATCH' with 200 status code.
40+-- | 'PATCH' with 200 status code.
36type Patch contentTypes a = Verb 'PATCH 200 contentTypes a
41type Patch contentTypes a = Verb 'PATCH 200 contentTypes a
37
42
43+-- * Other responses
44+
45+-- ** 201 Created
46+--
47+-- Indicates that a new resource has been created. The URI corresponding to the
48+-- resource should be given in the @Location@ header field.
49+--
50+-- If the resource cannot be created immediately, use 'PostAccepted'.
51+--
52+-- Consider using 'Servant.Utils.Links.safeLink' for the @Location@ header
53+-- field.
54+
38−-- 'HEAD' with 200 status code.
55+-- | 'POST' with 201 status code.
56+--
39−type Head contentTypes a = Verb 'HEAD 200 contentTypes a
57+type Created contentTypes a = Verb 'POST 201 contentTypes a
58+
59+
60+-- ** 202 Accepted
61+--
62+-- Indicates that the request has been accepted for processing, but the
63+-- processing has not yet completed. The status of the processing should be
64+-- included, as well as either a link to a status monitoring endpoint or an
65+-- estimate of when the processing will be finished.
66+
67+-- | 'GET' with 202 status code.
68+type GetAccepted contentTypes a = Verb 'GET 202 contentTypes a
69+-- | 'POST' with 202 status code.
70+type PostAccepted contentTypes a = Verb 'POST 202 contentTypes a
71+-- | 'DELETE' with 202 status code.
72+type DeleteAccepted contentTypes a = Verb 'DELETE 202 contentTypes a
73+-- | 'PATCH' with 202 status code.
74+type PatchAccepted contentTypes a = Verb 'PATCH 202 contentTypes a
75+-- | 'PUT' with 202 status code.
76+type PutAccepted contentTypes a = Verb 'PUT 202 contentTypes a
77+
78+
79+-- ** 203 Non-Authoritative Information
80+--
81+-- Indicates that the request has been successfully processed, but the
82+-- information may come from a third-party.
83+
84+-- | 'GET' with 203 status code.
85+type GetNonAuthoritative contentTypes a = Verb 'GET 203 contentTypes a
86+-- | 'POST' with 203 status code.
87+type PostNonAuthoritative contentTypes a = Verb 'POST 203 contentTypes a
88+-- | 'DELETE' with 203 status code.
89+type DeleteNonAuthoritative contentTypes a = Verb 'DELETE 203 contentTypes a
90+-- | 'PATCH' with 203 status code.
91+type PatchNonAuthoritative contentTypes a = Verb 'PATCH 203 contentTypes a
92+-- | 'PUT' with 203 status code.
93+type PutNonAuthoritative contentTypes a = Verb 'PUT 203 contentTypes a
94+
95+
96+-- ** 204 No Content
97+--
98+-- Indicates that no response body is being returned. Handlers for these must
99+-- return 'NoContent'.
100+--
101+-- If the document view should be reset, use @205 Reset Content@.
102+
103+-- | 'GET' with 204 status code.
104+type GetNoContent contentTypes = Verb 'GET 204 contentTypes NoContent
105+-- | 'POST' with 204 status code.
106+type PostNoContent contentTypes = Verb 'POST 204 contentTypes NoContent
107+-- | 'DELETE' with 204 status code.
108+type DeleteNoContent contentTypes = Verb 'DELETE 204 contentTypes NoContent
109+-- | 'PATCH' with 204 status code.
110+type PatchNoContent contentTypes = Verb 'PATCH 204 contentTypes NoContent
111+-- | 'PUT' with 204 status code.
112+type PutNoContent contentTypes = Verb 'PUT 204 contentTypes NoContent
113+
114+
115+-- ** 205 Reset Content
116+--
117+-- Indicates that no response body is being returned. Handlers for these must
118+-- return 'NoContent'.
119+--
120+-- If the document view should not be reset, use @204 No Content@.
121+
122+-- | 'GET' with 205 status code.
123+type GetResetContent contentTypes = Verb 'GET 205 contentTypes NoContent
124+-- | 'POST' with 205 status code.
125+type PostResetContent contentTypes = Verb 'POST 205 contentTypes NoContent
126+-- | 'DELETE' with 205 status code.
127+type DeleteResetContent contentTypes = Verb 'DELETE 205 contentTypes NoContent
128+-- | 'PATCH' with 205 status code.
129+type PatchResetContent contentTypes = Verb 'PATCH 205 contentTypes NoContent
130+-- | 'PUT' with 205 status code.
131+type PutResetContent contentTypes = Verb 'PUT 205 contentTypes NoContent
132+
133+
134+-- ** 206 Partial Content
135+--
136+-- Indicates that the server is delivering part of the resource due to a range
137+-- header in the request.
138+--
139+-- For more information, see <https://tools.ietf.org/html/rfc7233#section-4.1
140+-- RFC7233 Section 4.1>
141+
142+-- | 'GET' with 206 status code.
143+type GetPartialContent contentTypes = Verb 'GET 205 contentTypes NoContent
144+
145+data NoContent = NoContent
40
146
41class ReflectMethod a where
147class ReflectMethod a where
42 reflectMethod :: proxy a -> Method
148 reflectMethod :: proxy a -> Method