AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
request.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 <istream>
25#include <map>
26#include <memory>
27#include <optional>
28#include <string>
29#include <string_view>
30#include <utility>
31#include <vector>
32
33#include "codec/mediaType.hpp"
34
35#include "rest/headers.hpp"
36#include "rest/method.hpp"
37
38namespace anch::rest {
39
50 class ANCH_REST_COMMON_EXPORT Request {
51
52 // Attributes +
53 private:
55 anch::rest::Method _method;
56
58 std::string _path;
59
61 std::vector<std::pair<std::string, std::string>> _query;
62
64 anch::rest::Headers _headers;
65
67 std::unique_ptr<std::istream> _body;
68
70 std::map<std::string, std::string, std::less<>> _pathParameters;
71 // Attributes -
72
73 // Constructors +
74 public:
79
86 Request(anch::rest::Method method, std::string_view target);
87 // Constructors -
88
89 // Methods +
90 public:
96 void setTarget(std::string_view target);
97
105 std::optional<std::string_view> getQueryParameter(std::string_view name) const;
106
113 void addQueryParameter(std::string_view name, std::string_view value);
114
122 std::optional<std::string_view> getPathParameter(std::string_view name) const;
123
129 std::optional<anch::codec::MediaType> getContentType() const;
130
136 std::vector<anch::codec::MediaType> getAccept() const;
137
143 bool hasBody() const noexcept;
144
150 std::istream& getBody() const;
151
157 void setBody(std::unique_ptr<std::istream> body);
158
164 void setBody(std::string body);
165 // Methods -
166
167 // Accessors +
168 public:
174 anch::rest::Method getMethod() const noexcept;
175
181 void setMethod(anch::rest::Method method) noexcept;
182
188 const std::string& getPath() const noexcept;
189
195 void setPath(std::string_view path);
196
202 const std::vector<std::pair<std::string, std::string>>& getQueryParameters() const noexcept;
203
210
216 const anch::rest::Headers& getHeaders() const noexcept;
217
223 const std::map<std::string, std::string, std::less<>>& getPathParameters() const noexcept;
224
230 void setPathParameters(std::map<std::string, std::string, std::less<>> parameters);
231 // Accessors -
232
233 };
234
243 ANCH_REST_COMMON_EXPORT std::optional<std::string> percentDecode(std::string_view value, bool plusAsSpace = false);
244
252 ANCH_REST_COMMON_EXPORT std::string percentEncode(std::string_view value);
253
254}
Definition headers.hpp:62
anch::rest::Method getMethod() const noexcept
void addQueryParameter(std::string_view name, std::string_view value)
bool hasBody() const noexcept
void setBody(std::unique_ptr< std::istream > body)
void setMethod(anch::rest::Method method) noexcept
Request(anch::rest::Method method, std::string_view target)
std::vector< anch::codec::MediaType > getAccept() const
std::optional< std::string_view > getPathParameter(std::string_view name) const
const std::string & getPath() const noexcept
void setPath(std::string_view path)
void setTarget(std::string_view target)
std::optional< std::string_view > getQueryParameter(std::string_view name) const
anch::rest::Headers & getHeaders() noexcept
const std::vector< std::pair< std::string, std::string > > & getQueryParameters() const noexcept
void setPathParameters(std::map< std::string, std::string, std::less<> > parameters)
std::optional< anch::codec::MediaType > getContentType() const
const std::map< std::string, std::string, std::less<> > & getPathParameters() const noexcept
std::istream & getBody() const
AnCH REST library namespace.
Definition auth.hpp:29
Method
Definition method.hpp:36
std::string percentEncode(std::string_view value)
std::optional< std::string > percentDecode(std::string_view value, bool plusAsSpace=false)
AnCH framework base namespace.
Definition app.hpp:30