Thoth
A functional, expressive, asynchronous C++26 webdev library
Loading...
Searching...
No Matches
Response.hpp
Go to the documentation of this file.
1#pragma once
7
9
10
11namespace Thoth::Http {
12 struct RequestError;
13
14 template<class T>
16 std::ranges::output_range<T, char> ||
17 std::ranges::output_range<T, unsigned char> ||
18 std::ranges::output_range<T, std::byte>;
19
20
21 template<ResponseBodyConcept Body>
22 auto GetInserterIterator(Body& body);
23
24
25 template<MethodConcept Method = GetMethod, ResponseBodyConcept Body = std::string>
26 struct Response {
27 using MethodType = Method;
28
31 string statusMessage{};
33 Body body;
34
35 friend struct Client; // who construct it
36
37 template<class = void>
38 requires std::same_as<Body, string>
39 [[nodiscard]] std::expected<NJson::Json, RequestError> AsJson() const;
40
42 [[nodiscard]] bool Successful() const;
43
46 [[nodiscard]] Body MoveBody() &&;
47 private:
48
50 string&& statusMessage, Headers&& headers, Body&& body);
51
52 Response(ResponseHead&& head, Body&& body);
53 };
54
57
60
63
66}
67
68
69
70#include <Thoth/Http/Response/Response.tpp>
71
Definition Response.hpp:15
Definition Client.hpp:12
auto GetInserterIterator(Body &body)
StatusCodeEnum
Definition StatusCodeEnum.hpp:7
VersionEnum
Definition Request.hpp:11
Definition Client.hpp:64
This class stores the headers from HTTP.
Definition Headers.hpp:29
Definition ResponseHead.hpp:9
Definition ResponseHeaders.hpp:7
Definition Response.hpp:26
Method MethodType
Definition Response.hpp:27
bool Successful() const
Returns if the response is 2XX.
StatusCodeEnum status
Definition Response.hpp:30
string statusMessage
Definition Response.hpp:31
Body MoveBody() &&
Monad friendly move of the body, discarding the rest of the response. Recommended check for Successfu...
std::expected< NJson::Json, RequestError > AsJson() const
VersionEnum version
Definition Response.hpp:29
ResponseHeaders headers
Definition Response.hpp:32
Body body
Definition Response.hpp:33