kaycxx-http
HTTP client library
Loading...
Searching...
No Matches
kaycxx::http::buffered_response Class Reference

HTTP response with a buffered body. More...

#include <kaycxx/http/buffered_response.hpp>

Inheritance diagram for kaycxx::http::buffered_response:
Collaboration diagram for kaycxx::http::buffered_response:

Public Member Functions

 buffered_response (int status_code, std::string body, std::vector< kaycxx::http::header > headers={})
 Creates a buffered HTTP response.
std::string_view text () const &noexcept
 Returns a non-owning view of the response body without interpreting its contents.
std::string text () &&noexcept
 Moves the response body out of an expiring response.
nlohmann::json json () const
 Parses and returns the response body as JSON.
Public Member Functions inherited from kaycxx::http::response_base
int status_code () const noexcept
 Returns the HTTP status code.
const std::vector< kaycxx::http::header > & headers () const &noexcept
 Returns all response headers in their received order.
std::vector< kaycxx::http::headerheaders () &&noexcept
 Moves all response headers out of an expiring response.
std::optional< std::string_view > header (std::string_view name) const &noexcept
 Returns the first value of a response header using an ASCII case-insensitive name comparison.
std::optional< std::string > header (std::string_view name) &&noexcept
 Moves the first value of a response header out of an expiring response using an ASCII case-insensitive name comparison.
std::vector< std::string > headers (std::string_view name) const
 Returns all values of a response header using an ASCII case-insensitive name comparison.

Additional Inherited Members

Protected Member Functions inherited from kaycxx::http::response_base
 response_base (int status_code, std::vector< kaycxx::http::header > headers)
 Creates common HTTP response data.
 response_base (const response_base &)=default
 Copies common HTTP response data.
 response_base (response_base &&) noexcept=default
 Moves common HTTP response data.
response_baseoperator= (const response_base &)=default
 Copies common HTTP response data.
response_baseoperator= (response_base &&) noexcept=default
 Moves common HTTP response data.
 ~response_base ()=default
 Destroys common HTTP response data.

Detailed Description

HTTP response with a buffered body.

Constructor & Destructor Documentation

◆ buffered_response()

kaycxx::http::buffered_response::buffered_response ( int status_code,
std::string body,
std::vector< kaycxx::http::header > headers = {} )

Creates a buffered HTTP response.

Parameters
status_codeHTTP status code.
bodyResponse body.
headersResponse headers.

Member Function Documentation

◆ json()

nlohmann::json kaycxx::http::buffered_response::json ( ) const
nodiscard

Parses and returns the response body as JSON.

Returns
Parsed JSON value. An empty response body is returned as JSON null.
Exceptions
nlohmann::json::parse_errorWhen the response body does not contain valid JSON.

◆ text() [1/2]

std::string kaycxx::http::buffered_response::text ( ) &&
nodiscardnoexcept

Moves the response body out of an expiring response.

Returns
Response body.

◆ text() [2/2]

std::string_view kaycxx::http::buffered_response::text ( ) const &
nodiscardnoexcept

Returns a non-owning view of the response body without interpreting its contents.

The returned view remains valid until this response is destroyed, moved from or assigned a new value.

Returns
View of the response body.

The documentation for this class was generated from the following file: