1 module mars.StatusCode;
2 
3 /**
4  * HTTP Status Codes
5  * 
6  * This is a list of Hypertext Transfer Protocol (HTTP) response
7  * status codes
8  * 
9  * http://www.restapitutorial.com/httpstatuscodes.html
10  */
11 class StatusCode {
12 	
13 	/**
14 	 * Standard response for successful HTTP requests. The actual
15 	 * response will depend on the request method used. In a GET
16 	 * request, the response will contain an entity corresponding
17 	 * to the requested resource. In a POST request, the response
18 	 * will contain an entity describing or containing the result
19 	 * of the action.
20 	 */
21 	static immutable int OK = 200;
22 	
23 	/**
24 	 * The request has been fulfilled, resulting in the creation of
25 	 * a new resource.
26 	 */
27 	static immutable int CREATED = 201;
28 	
29 	/**
30 	 * The server successfully processed the request and is not
31 	 * returning any content.
32 	 */
33 	static immutable int NO_CONTENT = 204;
34 	
35 	/**
36 	 * The server cannot or will not process the request due to an
37 	 * apparent client error (e.g., malformed request syntax, too
38 	 * large size, invalid request message framing, or deceptive
39 	 * request routing).
40 	 */
41 	static immutable int BAD_REQUEST = 400;
42 	
43 	/**
44 	 * Similar to 403 Forbidden, but specifically for use when
45 	 * authentication is required and has failed or has not yet
46 	 * been provided. The response must include a WWW-Authenticate
47 	 * header field containing a challenge applicable to the
48 	 * requested resource.
49 	 */
50 	static immutable int UNAUTHORIZED = 401;
51 	
52 	/**
53 	 * The request was a valid request, but the server is refusing
54 	 * to respond to it. The user might be logged in but does not
55 	 * have the necessary permissions for the resource.
56 	 */
57 	static immutable int FORBIDDEN = 403;
58 	
59 	/**
60 	 * The requested resource could not be found but may be
61 	 * available in the future. Subsequent requests by the client
62 	 * are permissible.
63 	 */
64 	static immutable int NOT_FOUND = 404;
65 
66 	/**
67 	 * Indicates that the request could not be processed because of
68 	 * conflict in the request, such as an edit conflict between
69 	 * multiple simultaneous updates.
70 	 */
71 	static immutable int CONFLICT = 409;
72 
73 	// Help methods
74 	
75 	static bool isSuccess(int statusCode) {
76 		return statusCode / 100 == 2;
77 	}
78 	
79 	static bool isClientError(int statusCode) {
80 		return statusCode / 100 == 4;
81 	}
82 	
83 	static bool isServerError(int statusCode) {
84 		return statusCode / 100 == 5;
85 	}
86 }