21 #ifndef NETWORK_API_H_
22 #define NETWORK_API_H_
26 #include <cpprest/asyncrt_utils.h>
27 #include <cpprest/containerstream.h>
28 #include <cpprest/filestream.h>
29 #include <cpprest/http_listener.h>
30 #include <cpprest/json.h>
31 #include <cpprest/producerconsumerstream.h>
32 #include <cpprest/uri.h>
39 using namespace utility;
40 using namespace http::experimental::listener;
78 static void add_CORS_headers(http_response& res);
83 void handle__api__GET(http_request req);
84 void handle__api__config__GET(http_request req);
86 void handle__config__GET(http_request req);
87 void handle__user__context__GET(http_request req);
89 void handle__dataset__video_detail__GET(http_request req);
91 void handle__search__get_top_display__POST(http_request req);
92 void handle__search__get_som_display__POST(http_request req);
93 void handle__search__get_som_relocation_display__POST(http_request req);
94 void handle__search__keyword_autocomplete__GET(http_request req);
96 void handle__search__reset__POST(http_request req);
97 void handle__search__rescore__POST(http_request req);
98 void handle__search__like_frame__POST(http_request req);
99 void handle__search__bookmark_frame__POST(http_request req);
100 void handle__search__context__POST(http_request req);
101 void handle__search__context__GET(http_request req);
103 void handle__log__scroll__GET(http_request req);
104 void handle__log__text_query_change__GET(http_request req);
105 void handle__log__canvas_query_change__GET(http_request req);
107 void handle__eval_server__submit__POST(http_request req);
108 void handle__eval_server__login__POST(http_request req);
109 void handle__eval_server__logout__POST(http_request req);
124 const std::string& path,
125 std::function<
void(
NetworkApi*, http_request)> GET_handler = std::function<
void(
NetworkApi*, http_request)>{},
126 std::function<void(
NetworkApi*, http_request)> POST_handler = std::function<void(
NetworkApi*, http_request)>{},
127 std::function<void(NetworkApi*, http_request)> PUT_handler = std::function<void(NetworkApi*, http_request)>{},
128 std::function<void(NetworkApi*, http_request)> DEL_handler = std::function<void(NetworkApi*, http_request)>{});
136 RescoreMetadata extract_rescore_metadata(web::json::value& body);
144 std::vector<TextualQuery> extract_textual_query(web::json::value& body);
152 std::vector<RelocationQuery> extract_relocation_query(web::json::value& body);
160 std::vector<CanvasQuery> extract_canvas_query(web::json::value& body);
168 Filters extract_filters(web::json::value& body);
171 std::lock_guard<std::mutex>
exclusive_lock()
const {
return std::lock_guard<std::mutex>{ _req_mtx }; };
Class responsible for listening for HTTP requests and for handlling them using the core.
Definition: network-api.h:57
std::vector< http_listener > _endpoints
Vector of used endpoints.
Definition: network-api.h:185
Somhunter * _p_core
A pointer to the core that this API exposes.
Definition: network-api.h:179
std::mutex _req_mtx
Lock used to synchronize some requests.
Definition: network-api.h:188
ApiConfig _API_config
A private copy of config.
Definition: network-api.h:171
std::lock_guard< std::mutex > exclusive_lock() const
Definition: network-api.h:171
NetworkApi()=delete
Only single ctor overload is acceptable.
std::string _base_addr
Base HTTP API address.
Definition: network-api.h:182
The main C++ API of the SOMHunter Core.
Definition: somhunter.h:54
Definition: common-types.h:33
Definition: settings.h:52