Octane API Client
Loading...
Searching...
No Matches
fetch.h
Go to the documentation of this file.
1
11#ifndef OCTANE_API_CLIENT_INTERNAL_FETCH_H_
12#define OCTANE_API_CLIENT_INTERNAL_FETCH_H_
13
14#include <rapidjson/document.h>
15#include <rapidjson/encodings.h>
16#include <rapidjson/stringbuffer.h>
17#include <rapidjson/writer.h>
18
19#include <map>
20#include <string>
21#include <string_view>
22#include <variant>
23#include <vector>
24
25#include "./http_client.h"
27#include "include/result.h"
28
29namespace octane::internal {
36 std::variant<rapidjson::Document, std::vector<std::uint8_t>> body;
38 std::string mime;
42 std::string statusLine;
44 std::map<std::string,std::string> header;
45 };
46
55 class FetchBase {
56 public:
58 virtual ~FetchBase() noexcept = 0;
70 virtual Result<_, ErrorResponse> init() = 0;
88 virtual FetchResult request(HttpMethod method, std::string_view url) = 0;
108 std::string_view url,
109 const rapidjson::Document& body)
110 = 0;
132 std::string_view url,
133 std::string_view mimeType,
134 const std::vector<std::uint8_t>& body)
135 = 0;
136 };
144 class Fetch : public FetchBase {
145 std::string token;
146 std::string origin;
147 std::string baseUrl;
148 HttpClientBase* client;
149
150 public:
170 Fetch(std::string_view token,
171 std::string_view origin,
172 std::string_view baseUrl,
173 HttpClientBase* client);
174 virtual ~Fetch() noexcept;
178 virtual Result<_, ErrorResponse> init() override;
182 virtual FetchResult request(HttpMethod method,
183 std::string_view url) override;
187 virtual FetchResult request(HttpMethod method,
188 std::string_view url,
189 const rapidjson::Document& body) override;
193 virtual FetchResult request(HttpMethod method,
194 std::string_view url,
195 std::string_view mimeType,
196 const std::vector<std::uint8_t>& body) override;
197
198 private:
223 std::string_view origin,
224 std::string_view url,
225 const std::map<std::string, std::string>& headers,
226 const std::vector<std::uint8_t>& body);
227 };
228} // namespace octane::internal
229
230#endif // OCTANE_API_CLIENT_INTERNAL_FETCH_H_
Wrapper class that bifurcates the values indicated by normal and quasi-normal states.
Definition: result.h:38
HttpClientクラスを通じてHTTP通信を行うインタフェース。
Definition: fetch.h:55
virtual ~FetchBase() noexcept=0
Definition: fetch.cpp:21
virtual FetchResult request(HttpMethod method, std::string_view url)=0
APIへのボディ部を持たないリクエストを発行する。
virtual Result< _, ErrorResponse > init()=0
Fetchのインスタンスを初期化する。
HttpClientクラスを通じてHTTP通信を行う。
Definition: fetch.h:144
HTTP通信を行うインタフェース。
Definition: http_client.h:120
Error response.
HTTPクライアント。
Definition: api_bridge.cpp:25
HttpMethod
HTTPメソッドを表す列挙体。
Definition: http_client.h:28
Define type to represent the result, inspired by Rust's "Result".
Structure representing that it returns nothing.
Definition: result.h:222
General stucture to represent the error.
Definition: error_response.h:24
Fetchのレスポンスを表す構造体。
Definition: fetch.h:34
std::string statusLine
レスポンスのステータスライン。
Definition: fetch.h:42
std::map< std::string, std::string > header
レスポンスのヘッダ部(ステータスラインを除く)。
Definition: fetch.h:44
std::string mime
レスポンスのmime。
Definition: fetch.h:38
int statusCode
レスポンスのステータスコード。
Definition: fetch.h:40
std::variant< rapidjson::Document, std::vector< std::uint8_t > > body
レスポンスのボディ部。
Definition: fetch.h:36