Fawkes API  Fawkes Development Version
fawkes::WebviewRestApi Class Reference

#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...
 
WebReplyprocess_request (const WebRequest *request, const std::string &rest_url)
 Process REST API request. More...
 

Detailed Description

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.

Author
Tim Niemueller

Definition at line 225 of file rest_api.h.

Member Typedef Documentation

◆ Handler

typedef std::function<std::unique_ptr<WebReply>std::string, WebviewRestParams &)> fawkes::WebviewRestApi::Handler

REST API call handler function type.

Definition at line 231 of file rest_api.h.

Constructor & Destructor Documentation

◆ WebviewRestApi()

fawkes::WebviewRestApi::WebviewRestApi ( const std::string &  name,
fawkes::Logger logger 
)

Constructor.

Parameters
nameof the API. The API's name will be part of the URL, e.g., '/api/[COMPONENT-NAME]/...'.
loggerlogger for informative output

Definition at line 46 of file rest_api.cpp.

Member Function Documentation

◆ add_handler() [1/5]

void fawkes::WebviewRestApi::add_handler ( WebRequest::Method  method,
std::string  path,
Handler  handler 
)

Add handler function.

Parameters
methodHTTP method to react to
pathpath (after component base path) to react to
handlerhandler function

Definition at line 90 of file rest_api.cpp.

Referenced by BackendInfoRestApi::init(), TransformsRestApi::init(), ClipsRestApi::init(), ConfigurationRestApi::init(), PluginRestApi::init(), ClipsExecutiveRestApi::init(), ImageRestApi::init(), and BlackboardRestApi::init().

◆ add_handler() [2/5]

template<class O , class I >
void fawkes::WebviewRestApi::add_handler ( WebRequest::Method  method,
std::string  path,
std::function< O(I &, WebviewRestParams &)>  handler 
)
inline

Add handler function.

Parameters
methodHTTP method to react to
pathpath (after component base path) to react to
handlerhandler function

Definition at line 276 of file rest_api.h.

References 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().

◆ add_handler() [3/5]

template<class O >
void fawkes::WebviewRestApi::add_handler ( WebRequest::Method  method,
std::string  path,
std::function< O(WebviewRestParams &)>  handler 
)
inline

Add handler function.

Parameters
methodHTTP method to react to
pathpath (after component base path) to react to
handlerhandler function

Definition at line 353 of file rest_api.h.

References 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().

◆ add_handler() [4/5]

template<class I >
void fawkes::WebviewRestApi::add_handler ( WebRequest::Method  method,
std::string  path,
std::function< std::unique_ptr< WebReply >(I, WebviewRestParams &)>  handler 
)
inline

Add handler function.

Parameters
methodHTTP method to react to
pathpath (after component base path) to react to
handlerhandler function

Definition at line 320 of file rest_api.h.

References fawkes::WebReply::HTTP_INTERNAL_SERVER_ERROR, and fawkes::Exception::what_no_backtrace().

◆ add_handler() [5/5]

void fawkes::WebviewRestApi::add_handler ( WebRequest::Method  method,
std::string  path,
std::function< std::unique_ptr< WebReply >(WebviewRestParams &)>  handler 
)
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.

Parameters
methodHTTP method to react to
pathpath (after component base path) to react to
handlerhandler function

Definition at line 245 of file rest_api.h.

References fawkes::WebReply::HTTP_INTERNAL_SERVER_ERROR, and fawkes::Exception::what_no_backtrace().

◆ name()

const std::string & fawkes::WebviewRestApi::name ( ) const

Get name of component.

Returns
name of component.

Definition at line 58 of file rest_api.cpp.

References fawkes::WebRequest::method().

Referenced by fawkes::WebviewRestApiManager::~WebviewRestApiManager().

◆ process_request()

WebReply * fawkes::WebviewRestApi::process_request ( const WebRequest request,
const std::string &  rest_url 
)

Process REST API request.

Parameters
requestincoming request
rest_urlthe URL stripped of the base URL prefix
Returns
reply

Definition at line 69 of file rest_api.cpp.

◆ set_pretty_json()

void fawkes::WebviewRestApi::set_pretty_json ( bool  pretty)

Enable or disable pretty JSON printing globally.

Parameters
prettytrue to enable

Definition at line 99 of file rest_api.cpp.


The documentation for this class was generated from the following files: