MySQL 8.0.39
Source Code Documentation
rest_client.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2018, 2024, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is designed to work with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25#ifndef MYSQL_ROUTER_REST_CLIENT_H_INCLUDED
26#define MYSQL_ROUTER_REST_CLIENT_H_INCLUDED
27
29
30constexpr const char kRestAPIVersion[] = "20190715";
31
33 public:
34 RestClient(IOContext &io_ctx, const std::string &address, uint16_t port)
35 : http_client_{std::unique_ptr<HttpClient>{
36 new HttpClient(io_ctx, address, port)}} {}
37
38 RestClient(IOContext &io_ctx, const std::string &address, uint16_t port,
39 const std::string &username, const std::string &password)
40 : username_{username},
41 password_{password},
42 http_client_{std::unique_ptr<HttpClient>{
43 new HttpClient(io_ctx, address, port)}} {}
44
45 RestClient(IOContext &io_ctx, const HttpUri &u, const std::string &username,
46 const std::string &password)
47 : username_{username},
48 password_{password},
49 http_client_{std::unique_ptr<HttpClient>{
50 new HttpClient(io_ctx, u.get_host(), u.get_port())}} {}
51
52 // build a RestClient around an existing HttpClient object that's consumed
53 RestClient(std::unique_ptr<HttpClient> &&http_client)
54 : http_client_{std::move(http_client)} {}
55
56 HttpRequest request_sync(
57 HttpMethod::type method, const std::string &uri,
58 const std::string &request_body = {},
59 const std::string &content_type = "application/json");
60
61 operator bool() const { return http_client_->operator bool(); }
62
63 std::string error_msg() const { return http_client_->error_msg(); }
64
65 private:
66 std::string username_;
67 std::string password_;
68 std::unique_ptr<HttpClient> http_client_;
69};
70
71#endif
Definition: http_client.h:127
a HTTP request and response.
Definition: http_request.h:453
representation of HTTP URI.
Definition: http_request.h:391
std::string get_host() const
Definition: http_common.cc:358
uint16_t get_port() const
Definition: http_common.cc:368
IO Context for network operations.
Definition: http_client.h:43
Definition: rest_client.h:32
std::string error_msg() const
Definition: rest_client.h:63
RestClient(std::unique_ptr< HttpClient > &&http_client)
Definition: rest_client.h:53
std::string password_
Definition: rest_client.h:67
std::unique_ptr< HttpClient > http_client_
Definition: rest_client.h:68
std::string username_
Definition: rest_client.h:66
RestClient(IOContext &io_ctx, const std::string &address, uint16_t port)
Definition: rest_client.h:34
RestClient(IOContext &io_ctx, const std::string &address, uint16_t port, const std::string &username, const std::string &password)
Definition: rest_client.h:38
RestClient(IOContext &io_ctx, const HttpUri &u, const std::string &username, const std::string &password)
Definition: rest_client.h:45
#define HTTP_CLIENT_EXPORT
Definition: http_client_export.h:40
static char * password
Definition: mysql_secure_installation.cc:56
int type
Definition: http_request.h:253
Definition: gcs_xcom_synode.h:64
std::conditional_t< !std::is_array< T >::value, std::unique_ptr< T, detail::Deleter< T > >, std::conditional_t< detail::is_unbounded_array_v< T >, std::unique_ptr< T, detail::Array_deleter< std::remove_extent_t< T > > >, void > > unique_ptr
The following is a common type that is returned by all the ut::make_unique (non-aligned) specializati...
Definition: ut0new.h:2438
required uint64 port
Definition: replication_asynchronous_connection_failover.proto:33
constexpr const char kRestAPIVersion[]
Definition: rest_client.h:30