MySQL 8.3.0
Source Code Documentation
rest_client.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2018, 2023, 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 also distributed 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 included with MySQL.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23*/
24#ifndef MYSQL_ROUTER_REST_CLIENT_H_INCLUDED
25#define MYSQL_ROUTER_REST_CLIENT_H_INCLUDED
26
28
29constexpr const char kRestAPIVersion[] = "20190715";
30
32 public:
33 RestClient(IOContext &io_ctx, const std::string &address, uint16_t port)
34 : http_client_{std::unique_ptr<HttpClient>{
35 new HttpClient(io_ctx, address, port)}} {}
36
37 RestClient(IOContext &io_ctx, const std::string &address, uint16_t port,
38 const std::string &username, const std::string &password)
39 : username_{username},
40 password_{password},
41 http_client_{std::unique_ptr<HttpClient>{
42 new HttpClient(io_ctx, address, port)}} {}
43
44 RestClient(IOContext &io_ctx, const HttpUri &u, const std::string &username,
45 const std::string &password)
46 : username_{username},
47 password_{password},
48 http_client_{std::unique_ptr<HttpClient>{
49 new HttpClient(io_ctx, u.get_host(), u.get_port())}} {}
50
51 // build a RestClient around an existing HttpClient object that's consumed
52 RestClient(std::unique_ptr<HttpClient> &&http_client)
53 : http_client_{std::move(http_client)} {}
54
55 HttpRequest request_sync(
56 HttpMethod::type method, const std::string &uri,
57 const std::string &request_body = {},
58 const std::string &content_type = "application/json");
59
60 operator bool() const { return http_client_->operator bool(); }
61
62 std::string error_msg() const { return http_client_->error_msg(); }
63
64 private:
65 std::string username_;
66 std::string password_;
67 std::unique_ptr<HttpClient> http_client_;
68};
69
70#endif
Definition: http_client.h:126
a HTTP request and response.
Definition: http_request.h:452
representation of HTTP URI.
Definition: http_request.h:390
std::string get_host() const
Definition: http_common.cc:357
uint16_t get_port() const
Definition: http_common.cc:367
IO Context for network operations.
Definition: http_client.h:42
Definition: rest_client.h:31
std::string error_msg() const
Definition: rest_client.h:62
RestClient(std::unique_ptr< HttpClient > &&http_client)
Definition: rest_client.h:52
std::string password_
Definition: rest_client.h:66
std::unique_ptr< HttpClient > http_client_
Definition: rest_client.h:67
std::string username_
Definition: rest_client.h:65
RestClient(IOContext &io_ctx, const std::string &address, uint16_t port)
Definition: rest_client.h:33
RestClient(IOContext &io_ctx, const std::string &address, uint16_t port, const std::string &username, const std::string &password)
Definition: rest_client.h:37
RestClient(IOContext &io_ctx, const HttpUri &u, const std::string &username, const std::string &password)
Definition: rest_client.h:44
#define HTTP_CLIENT_EXPORT
Definition: http_client_export.h:39
static char * password
Definition: mysql_secure_installation.cc:57
int type
Definition: http_request.h:252
Definition: varlen_sort.h:174
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:2437
required uint64 port
Definition: replication_asynchronous_connection_failover.proto:32
constexpr const char kRestAPIVersion[]
Definition: rest_client.h:29