Fawkes API Fawkes Development Version
|
Webview REST API component. More...
#include <>>
Public Types | |
typedef std::function< std::unique_ptr< WebReply >(std::string, WebviewRestParams &)> | Handler |
REST API call handler function type. More... | |
Public Member Functions | |
WebviewRestApi (const std::string &name, fawkes::Logger *logger) | |
Constructor. More... | |
const std::string & | name () const |
Get name of component. More... | |
void | add_handler (WebRequest::Method method, std::string path, Handler handler) |
Add handler function. More... | |
void | set_pretty_json (bool pretty) |
Enable or disable pretty JSON printing globally. More... | |
void | add_handler (WebRequest::Method method, std::string path, std::function< std::unique_ptr< WebReply >(WebviewRestParams &)> handler) |
Add simple handler. More... | |
template<class O , class I > | |
void | add_handler (WebRequest::Method method, std::string path, std::function< O(I &, WebviewRestParams &)> handler) |
Add handler function. More... | |
template<class I > | |
void | add_handler (WebRequest::Method method, std::string path, std::function< std::unique_ptr< WebReply >(I, WebviewRestParams &)> handler) |
Add handler function. More... | |
template<class O > | |
void | add_handler (WebRequest::Method method, std::string path, std::function< O(WebviewRestParams &)> handler) |
Add handler function. More... | |
WebReply * | process_request (const WebRequest *request, const std::string &rest_url) |
Process REST API request. More... | |
Webview REST API component.
This class represents a specific REST API available through Webview. The API's name will be part of the URL, e.g., '/api/[COMPONENT-NAME]/...'. The REST API can process patterns according to the OpenAPI 3 specification.
Definition at line 220 of file rest_api.h.
typedef std::function<std::unique_ptr<WebReply>(std::string, WebviewRestParams &)> fawkes::WebviewRestApi::Handler |
REST API call handler function type.
Definition at line 226 of file rest_api.h.
fawkes::WebviewRestApi::WebviewRestApi | ( | const std::string & | name, |
fawkes::Logger * | logger | ||
) |
Constructor.
name | of the API. The API's name will be part of the URL, e.g., '/api/[COMPONENT-NAME]/...'. |
logger | logger for informative output |
Definition at line 41 of file rest_api.cpp.
void fawkes::WebviewRestApi::add_handler | ( | WebRequest::Method | method, |
std::string | path, | ||
Handler | handler | ||
) |
Add handler function.
method | HTTP method to react to |
path | path (after component base path) to react to |
handler | handler function |
Definition at line 85 of file rest_api.cpp.
Referenced by add_handler(), ClipsExecutiveRestApi::init(), ClipsRestApi::init(), BackendInfoRestApi::init(), BlackboardRestApi::init(), ConfigurationRestApi::init(), ImageRestApi::init(), PluginRestApi::init(), and TransformsRestApi::init().
|
inline |
Add handler function.
method | HTTP method to react to |
path | path (after component base path) to react to |
handler | handler function |
Definition at line 271 of file rest_api.h.
References add_handler(), fawkes::WebviewRestException::code(), fawkes::WebviewRestException::content_type(), fawkes::WebviewRestParams::has_query_arg(), fawkes::WebReply::HTTP_INTERNAL_SERVER_ERROR, fawkes::WebReply::HTTP_OK, fawkes::Logger::log_warn(), fawkes::WebviewRestParams::pretty_json(), fawkes::WebviewRestParams::set_pretty_json(), and fawkes::Exception::what_no_backtrace().
|
inline |
Add handler function.
method | HTTP method to react to |
path | path (after component base path) to react to |
handler | handler function |
Definition at line 348 of file rest_api.h.
References add_handler(), fawkes::WebviewRestException::code(), fawkes::WebviewRestException::content_type(), fawkes::WebviewRestParams::has_query_arg(), fawkes::WebReply::HTTP_INTERNAL_SERVER_ERROR, fawkes::WebReply::HTTP_OK, fawkes::Logger::log_warn(), fawkes::WebviewRestParams::pretty_json(), fawkes::WebviewRestParams::set_pretty_json(), and fawkes::Exception::what_no_backtrace().
|
inline |
Add handler function.
method | HTTP method to react to |
path | path (after component base path) to react to |
handler | handler function |
Definition at line 315 of file rest_api.h.
References add_handler(), fawkes::WebviewRestException::code(), fawkes::WebviewRestException::content_type(), fawkes::WebReply::HTTP_INTERNAL_SERVER_ERROR, and fawkes::Exception::what_no_backtrace().
|
inline |
Add simple handler.
For a handler that does not require input parameters and that outputs a WebviewRestReply instance, for example, only to indicate success.
method | HTTP method to react to |
path | path (after component base path) to react to |
handler | handler function |
Definition at line 240 of file rest_api.h.
References add_handler(), fawkes::WebviewRestException::code(), fawkes::WebviewRestException::content_type(), fawkes::WebReply::HTTP_INTERNAL_SERVER_ERROR, and fawkes::Exception::what_no_backtrace().
const std::string & fawkes::WebviewRestApi::name | ( | ) | const |
Get name of component.
Definition at line 53 of file rest_api.cpp.
Referenced by fawkes::WebviewRestApiManager::register_api(), and fawkes::WebviewRestApiManager::unregister_api().
WebReply * fawkes::WebviewRestApi::process_request | ( | const WebRequest * | request, |
const std::string & | rest_url | ||
) |
Process REST API request.
request | incoming request |
rest_url | the URL stripped of the base URL prefix |
Definition at line 64 of file rest_api.cpp.
References fawkes::WebRequest::body(), fawkes::WebRequest::get_values(), and fawkes::WebRequest::method().
void fawkes::WebviewRestApi::set_pretty_json | ( | bool | pretty | ) |
Enable or disable pretty JSON printing globally.
pretty | true to enable |
Definition at line 94 of file rest_api.cpp.