Function registerMethod

Synopsis

#include <lib/inc/drogon/HttpController.h>

template <typename FUNCTION>
static void registerMethod(FUNCTION &&function, const std::string &pattern, const std::vector< internal::HttpConstraint > &filtersAndMethods=std::vector< internal::HttpConstraint >{}, bool classNameInPath=true, const std::string &handlerName="")

Description

No description yet.

Source

Lines 65-109 in lib/inc/drogon/HttpController.h.

template <typename FUNCTION>
static void registerMethod(
    FUNCTION &&function,
    const std::string &pattern,
    const std::vector<internal::HttpConstraint> &filtersAndMethods =
        std::vector<internal::HttpConstraint>{},
    bool classNameInPath = true,
    const std::string &handlerName = "")
{
    if (classNameInPath)
    {
        std::string path = "/";
        path.append(HttpController<T>::classTypeName());
        LOG_TRACE << "classname:" << HttpController<T>::classTypeName();
        // transform(path.begin(), path.end(), path.begin(), tolower);
        std::string::size_type pos;
        while ((pos = path.find("::")) != std::string::npos)
        {
            path.replace(pos, 2, "/");
        }
        if (pattern.empty() || pattern[0] == '/')
            app().registerHandler(path + pattern,
                                  std::forward<FUNCTION>(function),
                                  filtersAndMethods,
                                  handlerName);
        else
            app().registerHandler(path + "/" + pattern,
                                  std::forward<FUNCTION>(function),
                                  filtersAndMethods,
                                  handlerName);
    }
    else
    {
        std::string path = pattern;
        if (path.empty() || path[0] != '/')
        {
            path = "/" + path;
        }
        app().registerHandler(path,
                              std::forward<FUNCTION>(function),
                              filtersAndMethods,
                              handlerName);
    }
}





Add Discussion as Guest

Log in to DocsForge