Decentralised Art Server
High-performance C++ backend that exposes HTML interface and a secure REST API for managing Performative Transactions entities
 
Loading...
Searching...
No Matches
http_codes.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <format>
4
5namespace dcn::http
6{
38 enum class Code
39 {
40 // Unknown, specially reserved
41 Unknown = 0,
42
43 // level 200
44 OK = 200,
45 Created = 201,
46 NoContent = 204,
47
48 // LEVEL 400
49 BadRequest = 400,
50 Unauthorized = 401,
51 Forbidden = 403,
52 NotFound = 404,
53
54 // LEVEL 500
57 GatewayTimeout = 504
58 };
59}
60
61template <>
62struct std::formatter<dcn::http::Code> : std::formatter<std::string> {
63 auto format(dcn::http::Code code, format_context& ctx) const {
64 switch(code)
65 {
66 // level 200
67 case dcn::http::Code::OK: return formatter<string>::format("200 OK", ctx);
68 case dcn::http::Code::Created: return formatter<string>::format("201 Created", ctx);
69 case dcn::http::Code::NoContent: return formatter<string>::format("204 No Content", ctx);
70
71 // LEVEL 400
72 case dcn::http::Code::BadRequest: return formatter<string>::format("400 Bad Request", ctx);
73 case dcn::http::Code::Unauthorized: return formatter<string>::format("401 Unauthorized", ctx);
74 case dcn::http::Code::Forbidden: return formatter<string>::format("403 Forbidden", ctx);
75 case dcn::http::Code::NotFound: return formatter<string>::format("404 Not Found", ctx);
76
77 // LEVEL 500
78 case dcn::http::Code::InternalServerError: return formatter<string>::format("500 Internal Server Error", ctx);
79 case dcn::http::Code::ServiceUnavailable: return formatter<string>::format("503 Service Unavailable", ctx);
80 case dcn::http::Code::GatewayTimeout: return formatter<string>::format("504 Gateway Timeout", ctx);
81
82 // Unknown
83 case dcn::http::Code::Unknown: return formatter<string>::format("Unknown", ctx);
84 }
85 return formatter<string>::format("", ctx);
86 }
87};
Definition http.hpp:16
Code
Enum to represent HTTP response status codes.
Definition http_codes.hpp:39
Definition decentralised_art.hpp:29
auto format(dcn::http::Code code, format_context &ctx) const
Definition http_codes.hpp:63