userver: userver/server/http/http_method.hpp Source File
⚠️ This is the documentation for an old userver version. Click here to switch to the latest version.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
http_method.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/server/http/http_method.hpp
4/// @brief @copybrief server::http::HttpMethod
5
6#include <string>
7
8#include <fmt/core.h>
9#include <userver/utils/fmt_compat.hpp>
10
11USERVER_NAMESPACE_BEGIN
12
13namespace server::http {
14
15/// @brief List of HTTP methods
16enum class HttpMethod {
17 kDelete,
18 kGet,
19 kHead,
20 kPost,
21 kPut,
22 kPatch,
23 kConnect,
24 kOptions,
25 kUnknown,
26};
27
28/// @brief Convert HTTP method enum value to string
29const std::string& ToString(HttpMethod method) noexcept;
30
31/// @brief Convert HTTP method string to enum value
32HttpMethod HttpMethodFromString(std::string_view method_str);
33
34} // namespace server::http
35
36USERVER_NAMESPACE_END
37
38template <>
39struct fmt::formatter<USERVER_NAMESPACE::server::http::HttpMethod> {
40 constexpr static auto parse(format_parse_context& ctx) { return ctx.begin(); }
41
42 template <typename FormatContext>
43 auto format(USERVER_NAMESPACE::server::http::HttpMethod method,
44 FormatContext& ctx) USERVER_FMT_CONST {
45 return fmt::format_to(ctx.out(), "{}",
46 USERVER_NAMESPACE::server::http::ToString(method));
47 }
48};