kaycxx-http
HTTP client library
Loading...
Searching...
No Matches
buffered_response.hpp
1// SPDX-FileCopyrightText: 2026 Klaus Reimer <k@ailis.de>
2// SPDX-License-Identifier: MIT
3
4#pragma once
5
6#include <kaycxx/http/header.hpp>
7#include <kaycxx/http/response_base.hpp>
8
9#include <nlohmann/json.hpp>
10
11#include <string>
12#include <string_view>
13#include <vector>
14
15namespace kaycxx::http {
16
19public:
27 buffered_response(int status_code, std::string body, std::vector<kaycxx::http::header> headers = {});
28
36 [[nodiscard]] std::string_view text() const & noexcept;
37
43 [[nodiscard]] std::string text() && noexcept;
44
51 [[nodiscard]] nlohmann::json json() const;
52
53private:
55 std::string body_;
56};
57
58} // namespace kaycxx::http
nlohmann::json json() const
Parses and returns the response body as JSON.
std::string_view text() const &noexcept
Returns a non-owning view of the response body without interpreting its contents.
buffered_response(int status_code, std::string body, std::vector< kaycxx::http::header > headers={})
Creates a buffered HTTP response.
int status_code() const noexcept
Returns the HTTP status code.
response_base(int status_code, std::vector< kaycxx::http::header > headers)
Creates common HTTP response data.
const std::vector< kaycxx::http::header > & headers() const &noexcept
Returns all response headers in their received order.