NetFlex  0.0.0
C++11 HTTP Server Library.
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
netflex::routing::route_matcher Class Reference

#include <route_matcher.hpp>

Public Member Functions

 route_matcher (const std::string &path)
 
 ~route_matcher (void)=default
 default dtor
 
 route_matcher (const route_matcher &)=default
 copy ctor
 
route_matcheroperator= (const route_matcher &)=default
 assignment operator
 
bool match (const std::string &path, params_t &params) const
 

Protected Member Functions

void build_match_regex (const std::string &path)
 
void match_get_params (const std::string &path, params_t &params) const
 

Protected Attributes

std::string m_match_regex_str
 
std::regex m_match_regex
 
std::vector< std::string > m_url_params
 

Detailed Description

hande the route matching logic build regex for a given route of the server and match requested path by http clients

Constructor & Destructor Documentation

◆ route_matcher()

netflex::routing::route_matcher::route_matcher ( const std::string &  path)
explicit

ctor

Parameters
pathpath associated to the route. It will be used to build an regex representation of the route to be used for matching

Member Function Documentation

◆ build_match_regex()

void netflex::routing::route_matcher::build_match_regex ( const std::string &  path)
protected

build matching regex that is, given a path, construct a regex that can be used by match() and store it in m_match_regex

Parameters
pathpath to be used for regex construction

◆ match()

bool netflex::routing::route_matcher::match ( const std::string &  path,
params_t &  params 
) const

match the given path with the underlying route

Parameters
pathpath to match
paramsplace where to store params of the requested path (for example /articles/1?author=simon) will store {article:1, author: simon} for underlying route /articles/:id. store nothing if mismatch
Returns
whether the path matched or not

◆ match_get_params()

void netflex::routing::route_matcher::match_get_params ( const std::string &  path,
params_t &  params 
) const
protected

match GET request params given a requested path

Parameters
pathpath to match
paramsplace where to store params of the requested path (for example /articles/1?author=simon) will store {author: simon}.

Member Data Documentation

◆ m_match_regex

std::regex netflex::routing::route_matcher::m_match_regex
protected

matching regex (regex object)

◆ m_match_regex_str

std::string netflex::routing::route_matcher::m_match_regex_str
protected

matching regex (string object)

◆ m_url_params

std::vector<std::string> netflex::routing::route_matcher::m_url_params
protected

url params to match, in order of appearance for example, for route /articles/:id/author/:name, this would be {id, name}


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