AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
response.hpp
1/*
2 ANCH Framework: ANother C++ Hack is a C++ framework based on C++23 standard
3 Copyright (C) 2012 Vincent Lachenal
4
5 This file is part of ANCH Framework.
6
7 ANCH Framework is free software: you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 ANCH Framework is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with ANCH Framework. If not, see <https://www.gnu.org/licenses/>.
19*/
20#pragma once
21
22#include "anch-rest-common-export.hpp"
23
24#include <functional>
25#include <ostream>
26#include <string>
27#include <string_view>
28
29#include "rest/headers.hpp"
30#include "rest/status.hpp"
31
32namespace anch::rest {
33
35 using BodyWriter = std::function<void(std::ostream&)>;
36
47 class ANCH_REST_COMMON_EXPORT Response {
48
49 // Attributes +
50 private:
52 anch::rest::Status _status;
53
55 anch::rest::Headers _headers;
56
59 // Attributes -
60
61 // Constructors +
62 public:
68 Response(anch::rest::Status status = anch::rest::Status::OK);
69 // Constructors -
70
71 // Methods +
72 public:
81 Response& header(std::string_view name, std::string_view value) &;
82
91 Response&& header(std::string_view name, std::string_view value) &&;
92
100 Response& contentType(std::string_view mediaType) &;
101
109 Response&& contentType(std::string_view mediaType) &&;
110
118 Response& body(std::string content) &;
119
127 Response&& body(std::string content) &&;
128
137
146
152 bool hasBody() const noexcept;
153
159 void writeBody(std::ostream& out) const;
160
166 std::string content() const;
167
171 void clearBody() noexcept;
172 // Methods -
173
174 // Accessors +
175 public:
181 anch::rest::Status getStatus() const noexcept;
182
188 void setStatus(anch::rest::Status status) noexcept;
189
196
202 const anch::rest::Headers& getHeaders() const noexcept;
203 // Accessors -
204
205 };
206
207}
Definition headers.hpp:62
Response && contentType(std::string_view mediaType) &&
anch::rest::Headers & getHeaders() noexcept
Response & contentType(std::string_view mediaType) &
Response && stream(anch::rest::BodyWriter writer) &&
Response(anch::rest::Status status=anch::rest::Status::OK)
Response & stream(anch::rest::BodyWriter writer) &
void clearBody() noexcept
void setStatus(anch::rest::Status status) noexcept
std::string content() const
bool hasBody() const noexcept
void writeBody(std::ostream &out) const
anch::rest::Status getStatus() const noexcept
Response && body(std::string content) &&
Response & body(std::string content) &
Response & header(std::string_view name, std::string_view value) &
Response && header(std::string_view name, std::string_view value) &&
AnCH REST library namespace.
Definition auth.hpp:29
Status
Definition status.hpp:36
std::function< void(std::ostream &)> BodyWriter
Definition response.hpp:35
AnCH framework base namespace.
Definition app.hpp:30