kaycxx-http
HTTP client library
Loading...
Searching...
No Matches
request_body.hpp
1// SPDX-FileCopyrightText: 2026 Klaus Reimer <k@ailis.de>
2// SPDX-License-Identifier: MIT
3
4#pragma once
5
6#include <kaycxx/http/sized_istream.hpp>
7
8#include <nlohmann/json.hpp>
9
10#include <cstddef>
11#include <cstdint>
12#include <functional>
13#include <iosfwd>
14#include <optional>
15#include <span>
16#include <string>
17#include <string_view>
18#include <variant>
19#include <vector>
20
21namespace kaycxx::http {
22
23class client;
24class multipart_form;
26
34public:
36 request_body() noexcept;
37
43 request_body(std::string_view body) noexcept;
44
50 request_body(const std::string& body) noexcept;
51
58 request_body(const char* body);
59
65 request_body(std::span<const std::byte> body) noexcept;
66
72 request_body(std::span<std::byte> body) noexcept;
73
79 request_body(const std::vector<std::byte>& body) noexcept;
80
86 request_body(std::istream& input) noexcept;
87
93 request_body(sized_istream input) noexcept;
94
100 request_body(const nlohmann::json& body) noexcept;
101
107 request_body(const url_encoded_form& body) noexcept;
108
114 request_body(const multipart_form& body) noexcept;
115
116private:
118 struct stream_data {
120 std::reference_wrapper<std::istream> input;
121
123 std::optional<std::uint64_t> size;
124 };
125
127 using value_type = std::variant<
128 std::monostate,
129 std::string_view,
130 std::span<const std::byte>,
131 stream_data,
132 std::reference_wrapper<const nlohmann::json>,
133 std::reference_wrapper<const url_encoded_form>,
134 std::reference_wrapper<const multipart_form>
135 >;
136
138 value_type value_{};
139
140 friend class client;
141};
142
143} // namespace kaycxx::http
Synchronous HTTP client.
Definition client.hpp:24
HTTP form encoded as multipart/form-data.
Definition multipart_form.hpp:20
request_body() noexcept
Creates an empty request body.
Input stream request body with a known byte count.
Definition sized_istream.hpp:15
HTTP form encoded as application/x-www-form-urlencoded.
Definition url_encoded_form.hpp:17