voicevox_client_cpp  0.0.0
A client library for VOICEVOX implemented in C++.
request.hpp
Go to the documentation of this file.
1 #ifndef VOICEVOX_CLIENT_CPP_REQUEST_HPP_
2 #define VOICEVOX_CLIENT_CPP_REQUEST_HPP_
3 #include <string>
4 #include <memory>
5 
6 #include <cpprest/http_msg.h>
7 #include <cpprest/json.h>
8 
10 {
11 
15 class Builder
16 {
17 public:
21  using SharedPtr = std::shared_ptr<Builder>;
22 
30  Builder(const std::string& path) noexcept(false)
31  : uri_builder_(path)
32  {
33  if (path.empty())
34  throw std::invalid_argument("Builder requires a value represents resource name");
35  }
36 
42  web::http::http_request get() noexcept
43  {
44  req_.set_request_uri(uri_builder_.to_uri());
45  return req_;
46  }
47 
57  Builder& method(const web::http::method& method)
58  {
59  req_.set_method(method);
60  return *this;
61  }
62 
71  Builder& header(const utility::string_t& key, const utility::string_t& value)
72  {
73  req_.headers().add(key, value);
74  return *this;
75  }
76 
84  Builder& body(const utility::string_t& body)
85  {
86  req_.set_body(body);
87  return *this;
88  }
89 
97  Builder& body(const web::json::value& body)
98  {
99  req_.set_body(body);
100  return *this;
101  }
102 
103 protected:
107  web::http::uri_builder uri_builder_;
108 
112  web::http::http_request req_;
113 };
114 
115 } // namespace voicevox_client_cpp::request
116 #endif // VOICEVOX_CLIENT_CPP_REQUEST_HPP_
web::http::http_request get() noexcept
Create and provide a request based on the settings provided so far.
Definition: request.hpp:42
Builder & body(const utility::string_t &body)
Set the body of the request. (String type)
Definition: request.hpp:84
Builder(const std::string &path) noexcept(false)
Initialize URI.
Definition: request.hpp:30
Builder & method(const web::http::method &method)
Set HTTP method to request.
Definition: request.hpp:57
web::http::http_request req_
The request object to be built.
Definition: request.hpp:112
Builder & header(const utility::string_t &key, const utility::string_t &value)
Set a header consists of a key and a value.
Definition: request.hpp:71
web::http::uri_builder uri_builder_
URI builder.
Definition: request.hpp:107
std::shared_ptr< Builder > SharedPtr
An alias of a pointer of this class.
Definition: request.hpp:21
Builder & body(const web::json::value &body)
Set the body of the request. (JSON type)
Definition: request.hpp:97
A base class for a group of builder classes.
Definition: request.hpp:16
Definition: client.hpp:16