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
47 // LEVEL 400
48 BadRequest = 400,
49 Unauthorized = 401,
50 Forbidden = 403,
51 NotFound = 404,
52
53 // LEVEL 500
56 GatewayTimeout = 504
57 };
58}
59
60template <>
61struct std::formatter<dcn::http::Code> : std::formatter<std::string> {
62 auto format(dcn::http::Code code, format_context& ctx) const {
63 switch(code)
64 {
65 // level 200
66 case dcn::http::Code::OK: return formatter<string>::format("200 OK", ctx);
67 case dcn::http::Code::Created: return formatter<string>::format("201 Created", ctx);
68
69 // LEVEL 400
70 case dcn::http::Code::BadRequest: return formatter<string>::format("400 Bad Request", ctx);
71 case dcn::http::Code::Unauthorized: return formatter<string>::format("401 Unauthorized", ctx);
72 case dcn::http::Code::Forbidden: return formatter<string>::format("403 Forbidden", ctx);
73 case dcn::http::Code::NotFound: return formatter<string>::format("404 Not Found", ctx);
74
75 // LEVEL 500
76 case dcn::http::Code::InternalServerError: return formatter<string>::format("500 Internal Server Error", ctx);
77 case dcn::http::Code::ServiceUnavailable: return formatter<string>::format("503 Service Unavailable", ctx);
78 case dcn::http::Code::GatewayTimeout: return formatter<string>::format("504 Gateway Timeout", ctx);
79
80 // Unknown
81 case dcn::http::Code::Unknown: return formatter<string>::format("Unknown", ctx);
82 }
83 return formatter<string>::format("", ctx);
84 }
85};
Definition http.hpp:16
Code
Enum to represent HTTP response status codes.
Definition http_codes.hpp:39
Definition decentralised_art.hpp:30
auto format(dcn::http::Code code, format_context &ctx) const
Definition http_codes.hpp:62