Fawkes API  Fawkes Development Version
fawkes::WebviewRouter< T > Class Template Reference

URL path router. More...

#include <router.h>

Inheritance diagram for fawkes::WebviewRouter< T >:

Public Member Functions

T & find_handler (const WebRequest *request, std::map< std::string, std::string > &path_args)
 Find a handler. More...
 
T & find_handler (WebRequest::Method method, const std::string &path, std::map< std::string, std::string > &path_args)
 Find a handler. More...
 
void add (WebRequest::Method method, const std::string &path, T handler, int weight)
 Add a handler with weight. More...
 
void add (WebRequest::Method method, const std::string &path, T handler)
 Add a handler. More...
 
void remove (WebRequest::Method method, const std::string &path)
 Remove a handler. More...
 

Detailed Description

template<typename T>
class fawkes::WebviewRouter< T >

URL path router.

Register URL path patterns and some handler or item. Then match it later to request URLs to retrieve this very handler or item if the pattern matches the URL.

Author
Tim Niemueller

Definition at line 42 of file rest_api.h.

Member Function Documentation

◆ add() [1/2]

template<typename T>
void fawkes::WebviewRouter< T >::add ( WebRequest::Method  method,
const std::string &  path,
handler,
int  weight 
)
inline

Add a handler with weight.

Parameters
methodHTTP method to match for
pathpath pattern. A pattern may contain "{var}" segments for a URL. These will match an element of the path, i.e., a string not containing a slash. If a pattern has the form {var+} then it may contain a slash and therefore match multiple path segments. The handler would receive an entry named "var" in the parameters path arguments.
handlerhandler to store
weighthigher weight means the handler is tried later by the router. The default is 0.

Definition at line 103 of file router.h.

Referenced by fawkes::WebviewRouter< Handler >::add().

◆ add() [2/2]

template<typename T>
void fawkes::WebviewRouter< T >::add ( WebRequest::Method  method,
const std::string &  path,
handler 
)
inline

Add a handler.

Parameters
methodHTTP method to match for
pathpath pattern. A pattern may contain "{var}" segments for a URL. These will match an element of the path, i.e., a string not containing a slash. If a pattern has the form {var+} then it may contain a slash and therefore match multiple path segments. The handler would receive an entry named "var" in the parameters path arguments.
handlerhandler to store

Definition at line 127 of file router.h.

◆ find_handler() [1/2]

template<typename T>
T& fawkes::WebviewRouter< T >::find_handler ( const WebRequest request,
std::map< std::string, std::string > &  path_args 
)
inline

Find a handler.

Parameters
requestincoming request object
path_argsupon successful completion, will contain mappings from path patterns to matched segments of the URL.
Returns
matched handler
Exceptions
NullPointerExceptionthrown if no handler could be found

Definition at line 54 of file router.h.

◆ find_handler() [2/2]

template<typename T>
T& fawkes::WebviewRouter< T >::find_handler ( WebRequest::Method  method,
const std::string &  path,
std::map< std::string, std::string > &  path_args 
)
inline

Find a handler.

Parameters
methodHTTP method of the request
pathpath to match against stored paths
path_argsupon successful completion, will contain mappings from path patterns to matched segments of the URL.
Returns
matched handler
Exceptions
NullPointerExceptionthrown if no handler could be found

Definition at line 77 of file router.h.

◆ remove()

template<typename T>
void fawkes::WebviewRouter< T >::remove ( WebRequest::Method  method,
const std::string &  path 
)
inline

Remove a handler.

Parameters
methodHTTP method to match for
pathpath pattern that equals the one given when adding.

Definition at line 137 of file router.h.


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