Thoth
A functional, expressive, asynchronous C++26 webdev library
Loading...
Searching...
No Matches
PostMethod.hpp
Go to the documentation of this file.
1#pragma once
3
4namespace Thoth::Http {
5 struct PostMethod {
6 static constexpr std::string_view MethodName() { return "POST"; }
7 static constexpr bool IsSafe() { return false; }
8 static constexpr bool IsIdempotent() { return false; }
9
10 static WebResultOper ValidateRequest(string_view body, const Url& url, const Headers& headers) {
11 return {};
12 }
13
14 static WebResultOper ValidateResponse(StatusCodeEnum statusCode, string_view body, const Url& url, const Headers& headers) {
15 if ((statusCode == StatusCodeEnum::NO_CONTENT || statusCode == StatusCodeEnum::NOT_MODIFIED) && !body.empty())
16 return std::unexpected{ StatusCodeEnum::BAD_GATEWAY };
17
18
19 if (statusCode == StatusCodeEnum::CREATED && !headers.Exists("Location"))
20 return std::unexpected{ StatusCodeEnum::BAD_GATEWAY };
21
22 return {};
23 }
24 };
25
26 static_assert(MethodConcept<PostMethod>);
27}
Definition Client.hpp:12
StatusCodeEnum
Definition StatusCodeEnum.hpp:7
WebResult< std::monostate > WebResultOper
Definition StatusCodeEnum.hpp:111
std::string_view string_view
Definition Url.hpp:7
This class stores the headers from HTTP.
Definition Headers.hpp:29
bool Exists(HeaderKeyRef key) const
check if a key exists.
Definition PostMethod.hpp:5
static constexpr bool IsSafe()
Definition PostMethod.hpp:7
static constexpr std::string_view MethodName()
Definition PostMethod.hpp:6
static constexpr bool IsIdempotent()
Definition PostMethod.hpp:8
static WebResultOper ValidateResponse(StatusCodeEnum statusCode, string_view body, const Url &url, const Headers &headers)
Definition PostMethod.hpp:14
static WebResultOper ValidateRequest(string_view body, const Url &url, const Headers &headers)
Definition PostMethod.hpp:10
Definition Url.hpp:10