AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
anch::rest::Response Class Reference

#include <response.hpp>

Collaboration diagram for anch::rest::Response:

Public Member Functions

 Response (anch::rest::Status status=anch::rest::Status::OK)
Response & header (std::string_view name, std::string_view value) &
Response && header (std::string_view name, std::string_view value) &&
Response & contentType (std::string_view mediaType) &
Response && contentType (std::string_view mediaType) &&
Response & body (std::string content) &
Response && body (std::string content) &&
Response & stream (anch::rest::BodyWriter writer) &
Response && stream (anch::rest::BodyWriter writer) &&
bool hasBody () const noexcept
void writeBody (std::ostream &out) const
std::string content () const
void clearBody () noexcept
anch::rest::Status getStatus () const noexcept
void setStatus (anch::rest::Status status) noexcept
anch::rest::Headers & getHeaders () noexcept
const anch::rest::Headers & getHeaders () const noexcept

Detailed Description

HTTP response.
The body is written by a function when the response is sent, which allows streaming.
Setters return the response to chain them, on lvalues and on temporaries:

return anch::rest::Response(anch::rest::Status::CREATED).header(anch::rest::header::LOCATION, "/pets/1");
Author
Vincent Lachenal
Since
0.2

Constructor & Destructor Documentation

◆ Response()

anch::rest::Response::Response ( anch::rest::Status status = anch::rest::Status::OK)

Response constructor

Parameters
statusthe status

Member Function Documentation

◆ body() [1/2]

Response & anch::rest::Response::body ( std::string content) &

Set body content

Parameters
contentthe body content
Returns
this
Here is the call graph for this function:

◆ body() [2/2]

Response && anch::rest::Response::body ( std::string content) &&

Set body content

Parameters
contentthe body content
Returns
this
Here is the call graph for this function:

◆ clearBody()

void anch::rest::Response::clearBody ( )
noexcept

Remove body (headers are kept)

Here is the call graph for this function:

◆ content()

std::string anch::rest::Response::content ( ) const

Get body content (body is written in a string)

Returns
the body content, empty when there is no body
Here is the call graph for this function:

◆ contentType() [1/2]

Response & anch::rest::Response::contentType ( std::string_view mediaType) &

Set Content-Type header

Parameters
mediaTypethe media type
Returns
this
Here is the call graph for this function:

◆ contentType() [2/2]

Response && anch::rest::Response::contentType ( std::string_view mediaType) &&

Set Content-Type header

Parameters
mediaTypethe media type
Returns
this
Here is the call graph for this function:

◆ getHeaders() [1/2]

const anch::rest::Headers & anch::rest::Response::getHeaders ( ) const
noexcept

Headers getter

Returns
the headers
Here is the call graph for this function:

◆ getHeaders() [2/2]

anch::rest::Headers & anch::rest::Response::getHeaders ( )
noexcept

Headers getter

Returns
the headers
Here is the call graph for this function:

◆ getStatus()

anch::rest::Status anch::rest::Response::getStatus ( ) const
noexcept

Status getter

Returns
the status
Here is the call graph for this function:

◆ hasBody()

bool anch::rest::Response::hasBody ( ) const
noexcept

Check if response has a body

Returns
true when response has a body

◆ header() [1/2]

Response & anch::rest::Response::header ( std::string_view name,
std::string_view value ) &

Set header value

Parameters
namethe header name
valuethe header value
Returns
this
Here is the call graph for this function:

◆ header() [2/2]

Response && anch::rest::Response::header ( std::string_view name,
std::string_view value ) &&

Set header value

Parameters
namethe header name
valuethe header value
Returns
this
Here is the call graph for this function:

◆ setStatus()

void anch::rest::Response::setStatus ( anch::rest::Status status)
noexcept

Status setter

Parameters
statusthe status
Here is the call graph for this function:

◆ stream() [1/2]

Response & anch::rest::Response::stream ( anch::rest::BodyWriter writer) &

Set body writer

Parameters
writerthe function which writes the body
Returns
this
Here is the call graph for this function:

◆ stream() [2/2]

Response && anch::rest::Response::stream ( anch::rest::BodyWriter writer) &&

Set body writer

Parameters
writerthe function which writes the body
Returns
this
Here is the call graph for this function:

◆ writeBody()

void anch::rest::Response::writeBody ( std::ostream & out) const

Write body. Nothing is written when there is no body.

Parameters
outthe output stream
Here is the call graph for this function:

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