MySQL 9.1.0
Source Code Documentation
rest_api_plugin.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2019, 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
26#ifndef MYSQLROUTER_REST_API_PLUGIN_INCLUDED
27#define MYSQLROUTER_REST_API_PLUGIN_INCLUDED
28
30
31#include <list>
32#include <regex>
33#include <shared_mutex>
34
35class RestApi {
36 public:
37 RestApi(const std::string &uri_prefix, const std::string &uri_prefix_regex);
38
39 RestApi(const RestApi &) = delete;
40 RestApi &operator=(const RestApi &) = delete;
41
42 RestApi(RestApi &&) = delete;
43 RestApi &operator=(RestApi &&) = delete;
44
45 /**
46 * process the spec's Json JsonDocument.
47 */
49
50 using PathList =
51 std::list<std::tuple<std::regex, std::unique_ptr<BaseRestApiHandler>>>;
52
53 /**
54 * add handler for URI path.
55 */
56 void add_path(const std::string &path,
57 std::unique_ptr<BaseRestApiHandler> handler);
58
59 /**
60 * remove handle for URI path.
61 */
62 void remove_path(const std::string &path);
63
64 /**
65 * handle request for all register URI paths.
66 *
67 * if no handler accepts the request, a HTTP response with status 404 will be
68 * sent.
69 */
71
72 /**
73 * get the uri path prefix.
74 */
75 std::string uri_prefix() const { return uri_prefix_; }
76
77 /**
78 * get the regex for the URI path prefix.
79 */
80 std::string uri_prefix_regex() const { return uri_prefix_regex_; }
81
82 /**
83 * get the spec as JSON.
84 */
85 std::string spec();
86
87 protected:
88 std::string uri_prefix_;
89 std::string uri_prefix_regex_;
90
91 std::shared_timed_mutex rest_api_handler_mutex_;
93 std::tuple<std::string, std::regex, std::unique_ptr<BaseRestApiHandler>>>
95
96 std::mutex spec_doc_mutex_;
98};
99
100#endif
void(*)(JsonDocument &spec_doc) SpecProcessor
processor for the RestAPI's spec.
Definition: rest_api_component.h:126
rapidjson::GenericDocument< rapidjson::UTF8<>, rapidjson::CrtAllocator > JsonDocument
Definition: rest_api_component.h:99
Definition: rest_api_plugin.h:35
RestApi(const std::string &uri_prefix, const std::string &uri_prefix_regex)
Definition: rest_api_plugin.cc:133
std::mutex spec_doc_mutex_
Definition: rest_api_plugin.h:96
void process_spec(RestApiComponent::SpecProcessor spec_processor)
process the spec's Json JsonDocument.
Definition: rest_api_plugin.cc:162
std::string uri_prefix_regex_
Definition: rest_api_plugin.h:89
std::list< std::tuple< std::string, std::regex, std::unique_ptr< BaseRestApiHandler > > > rest_api_handlers_
Definition: rest_api_plugin.h:94
RestApi(const RestApi &)=delete
std::string spec()
get the spec as JSON.
Definition: rest_api_plugin.cc:168
std::shared_timed_mutex rest_api_handler_mutex_
Definition: rest_api_plugin.h:91
std::string uri_prefix_
Definition: rest_api_plugin.h:88
RestApi(RestApi &&)=delete
RestApiComponent::JsonDocument spec_doc_
Definition: rest_api_plugin.h:97
std::string uri_prefix() const
get the uri path prefix.
Definition: rest_api_plugin.h:75
std::list< std::tuple< std::regex, std::unique_ptr< BaseRestApiHandler > > > PathList
Definition: rest_api_plugin.h:51
void handle_paths(http::base::Request &req)
handle request for all register URI paths.
Definition: rest_api_plugin.cc:204
void remove_path(const std::string &path)
remove handle for URI path.
Definition: rest_api_plugin.cc:194
RestApi & operator=(const RestApi &)=delete
void add_path(const std::string &path, std::unique_ptr< BaseRestApiHandler > handler)
add handler for URI path.
Definition: rest_api_plugin.cc:180
RestApi & operator=(RestApi &&)=delete
std::string uri_prefix_regex() const
get the regex for the URI path prefix.
Definition: rest_api_plugin.h:80
The handler class is the interface for dynamically loadable storage engines.
Definition: handler.h:4583
Definition: request.h:44
static char * path
Definition: mysqldump.cc:149
std::list< T, ut::allocator< T > > list
Specialization of list which uses ut_allocator.
Definition: ut0new.h:2880