kaycxx-http
HTTP client library
Loading...
Searching...
No Matches
client.hpp
1// SPDX-FileCopyrightText: 2026 Klaus Reimer <k@ailis.de>
2// SPDX-License-Identifier: MIT
3
4#pragma once
5
6#include <kaycxx/http/buffered_response.hpp>
7#include <kaycxx/http/request_body.hpp>
8#include <kaycxx/http/request_options.hpp>
9#include <kaycxx/http/response_body.hpp>
10#include <kaycxx/http/streamed_response.hpp>
11
12#include <memory>
13#include <string_view>
14
15namespace kaycxx::http {
16
24class client {
25public:
32
41 explicit client(request_options default_options);
42
45
46 client(const client&) = delete;
47 client& operator=(const client&) = delete;
48
54 client(client&& other) noexcept;
55
62 client& operator=(client&& other) noexcept;
63
74 [[nodiscard]] buffered_response request(std::string_view method, std::string_view url, const request_options& options = {});
75
89 std::string_view method,
90 std::string_view url,
91 request_body body,
92 const request_options& options = {}
93 );
94
110 std::string_view method,
111 std::string_view url,
112 response_body output,
113 const request_options& options = {}
114 );
115
133 std::string_view method,
134 std::string_view url,
135 request_body body,
136 response_body output,
137 const request_options& options = {}
138 );
139
149 [[nodiscard]] buffered_response get(std::string_view url, const request_options& options = {});
150
162 [[nodiscard]] buffered_response get(std::string_view url, request_body body, const request_options& options = {});
163
174 [[nodiscard]] streamed_response get(std::string_view url, response_body output, const request_options& options = {});
175
188 [[nodiscard]] streamed_response get(
189 std::string_view url,
190 request_body body,
191 response_body output,
192 const request_options& options = {}
193 );
194
204 [[nodiscard]] buffered_response post(std::string_view url, const request_options& options = {});
205
217 [[nodiscard]] buffered_response post(std::string_view url, request_body body, const request_options& options = {});
218
229 [[nodiscard]] streamed_response post(std::string_view url, response_body output, const request_options& options = {});
230
243 [[nodiscard]] streamed_response post(
244 std::string_view url,
245 request_body body,
246 response_body output,
247 const request_options& options = {}
248 );
249
259 [[nodiscard]] buffered_response put(std::string_view url, const request_options& options = {});
260
272 [[nodiscard]] buffered_response put(std::string_view url, request_body body, const request_options& options = {});
273
284 [[nodiscard]] streamed_response put(std::string_view url, response_body output, const request_options& options = {});
285
298 [[nodiscard]] streamed_response put(
299 std::string_view url,
300 request_body body,
301 response_body output,
302 const request_options& options = {}
303 );
304
314 [[nodiscard]] buffered_response del(std::string_view url, const request_options& options = {});
315
327 [[nodiscard]] buffered_response del(std::string_view url, request_body body, const request_options& options = {});
328
339 [[nodiscard]] streamed_response del(std::string_view url, response_body output, const request_options& options = {});
340
353 [[nodiscard]] streamed_response del(
354 std::string_view url,
355 request_body body,
356 response_body output,
357 const request_options& options = {}
358 );
359
360private:
362 class impl;
363
370 [[nodiscard]] impl& require_impl();
371
373 std::unique_ptr<impl> impl_;
374};
375
376} // namespace kaycxx::http
HTTP response with a buffered body.
Definition buffered_response.hpp:18
streamed_response put(std::string_view url, response_body output, const request_options &options={})
Sends a PUT request and streams the successful response body to an output stream.
buffered_response request(std::string_view method, std::string_view url, const request_options &options={})
Sends an HTTP request and buffers the response body.
buffered_response get(std::string_view url, const request_options &options={})
Sends a GET request and buffers the response body.
streamed_response get(std::string_view url, request_body body, response_body output, const request_options &options={})
Sends a GET request with a body and streams the successful response body to an output stream.
client & operator=(client &&other) noexcept
Move-assigns an HTTP client.
buffered_response put(std::string_view url, const request_options &options={})
Sends a PUT request and buffers the response body.
client()
Creates an HTTP client.
buffered_response get(std::string_view url, request_body body, const request_options &options={})
Sends a GET request with a body and buffers the response body.
buffered_response del(std::string_view url, request_body body, const request_options &options={})
Sends a DELETE request with a body and buffers the response body.
buffered_response del(std::string_view url, const request_options &options={})
Sends a DELETE request and buffers the response body.
client(request_options default_options)
Creates an HTTP client with default request options.
streamed_response del(std::string_view url, response_body output, const request_options &options={})
Sends a DELETE request and streams the successful response body to an output stream.
streamed_response del(std::string_view url, request_body body, response_body output, const request_options &options={})
Sends a DELETE request with a body and streams the successful response body to an output stream.
streamed_response request(std::string_view method, std::string_view url, request_body body, response_body output, const request_options &options={})
Sends an HTTP request with a body and streams the successful response body to an output stream.
streamed_response post(std::string_view url, request_body body, response_body output, const request_options &options={})
Sends a POST request with a body and streams the successful response body to an output stream.
client(client &&other) noexcept
Moves an HTTP client.
buffered_response request(std::string_view method, std::string_view url, request_body body, const request_options &options={})
Sends an HTTP request with a body and buffers the response body.
streamed_response post(std::string_view url, response_body output, const request_options &options={})
Sends a POST request and streams the successful response body to an output stream.
streamed_response request(std::string_view method, std::string_view url, response_body output, const request_options &options={})
Sends an HTTP request and streams the successful response body to an output stream.
~client()
Destroys the HTTP client.
streamed_response put(std::string_view url, request_body body, response_body output, const request_options &options={})
Sends a PUT request with a body and streams the successful response body to an output stream.
buffered_response put(std::string_view url, request_body body, const request_options &options={})
Sends a PUT request with a body and buffers the response body.
streamed_response get(std::string_view url, response_body output, const request_options &options={})
Sends a GET request and streams the successful response body to an output stream.
buffered_response post(std::string_view url, request_body body, const request_options &options={})
Sends a POST request with a body and buffers the response body.
buffered_response post(std::string_view url, const request_options &options={})
Sends a POST request and buffers the response body.
Non-owning HTTP request body descriptor.
Definition request_body.hpp:33
Non-owning HTTP response body destination.
Definition response_body.hpp:14
Successful HTTP response whose body has been written to an output stream.
Definition streamed_response.hpp:14
Optional HTTP request configuration.
Definition request_options.hpp:23