Fawkes API  Fawkes Development Version
fawkes::WebviewRestApi Class Reference

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...
 
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 220 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 226 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 41 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 85 of file rest_api.cpp.

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

◆ add_handler() [2/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 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().

◆ add_handler() [3/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() [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 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().

◆ add_handler() [5/5]

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

◆ name()

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

Get name of component.

Returns
name of component.

Definition at line 53 of file rest_api.cpp.

Referenced by fawkes::WebviewRestApiManager::register_api(), and fawkes::WebviewRestApiManager::unregister_api().

◆ 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 64 of file rest_api.cpp.

References fawkes::WebRequest::body(), fawkes::WebRequest::get_values(), and fawkes::WebRequest::method().

◆ 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 94 of file rest_api.cpp.


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