# HttpRouter.hpp

This File On Github
Ask A Question

API: latest
module: oatpp
#include "oatpp/web/server/HttpRouter.hpp"

# HttpRouterTemplate

HttpRouter is responsible for routing http requests by method and path-pattern.

namespace oatpp { namespace web { namespace server { 
  template<typename RouterEndpoint>
  class HttpRouterTemplate : public oatpp::base::Countable {}
}}}

# Typedefs

Type Name Summary
data::share::StringKeyLabel StringKeyLabel Convenience typedef for oatpp::data::share::StringKeyLabel.
web::url::mapping::Router<RouterEndpoint> BranchRouter oatpp::web::url::mapping::Router
std::unordered_map<StringKeyLabel, std::shared_ptr<BranchRouter>> BranchMap Http method to HttpRouter::BranchRouter map. Meaning that for each http method like ["GET", "POST", ...] there is a separate HttpRouter::BranchRouter.

# Methods

Return Type Name Summary
[none] HttpRouterTemplate Default Constructor.
std::shared_ptr<HttpRouterTemplate> createShared Create shared HttpRouter.
void route Route URL to Endpoint by method, and pathPattern.
BranchRouter::Route getRoute Resolve http method and path to oatpp::web::url::mapping::Router::Route
void logRouterMappings Print out all router mapping.

# HttpRouterTemplate::StringKeyLabel

Convenience typedef for oatpp::data::share::StringKeyLabel.

typedef data::share::StringKeyLabel StringKeyLabel

# HttpRouterTemplate::BranchRouter

oatpp::web::url::mapping::Router

typedef web::url::mapping::Router<RouterEndpoint> BranchRouter

# HttpRouterTemplate::BranchMap

Http method to HttpRouter::BranchRouter map. Meaning that for each http method like ["GET", "POST", ...] there is a separate HttpRouter::BranchRouter.

typedef std::unordered_map<StringKeyLabel, std::shared_ptr<BranchRouter>> BranchMap

# HttpRouterTemplate::HttpRouterTemplate

Default Constructor.

HttpRouterTemplate() = default

# HttpRouterTemplate::createShared

Create shared HttpRouter.

  • @return - std::shared_ptr to HttpRouter.

static std::shared_ptr<HttpRouterTemplate> createShared()

# HttpRouterTemplate::route

Route URL to Endpoint by method, and pathPattern.

  • @param method - http method like ["GET", "POST", etc.].
  • @param pathPattern - url path pattern. ex.: "/path/to/resource/with/{param1}/{param2}".
  • @param endpoint - router endpoint.

void route(const oatpp::String& method, const oatpp::String& pathPattern, const RouterEndpoint& endpoint)

# HttpRouterTemplate::getRoute

Resolve http method and path to oatpp::web::url::mapping::Router::Route

typename BranchRouter::Route getRoute(const StringKeyLabel& method, const StringKeyLabel& path)

# HttpRouterTemplate::logRouterMappings

Print out all router mapping.

void logRouterMappings()

# HttpRouter

Default HttpRouter.

namespace oatpp { namespace web { namespace server { 
  class HttpRouter : public HttpRouterTemplate<std::shared_ptr<HttpRequestHandler>> {}
}}}

# Methods

Return Type Name Summary
std::shared_ptr<HttpRouter> createShared Create shared HttpRouter.
std::shared_ptr<server::api::ApiController> addController Add controller and route its' endpoints.

# HttpRouter::createShared

Create shared HttpRouter.

  • @return

static std::shared_ptr<HttpRouter> createShared()

# HttpRouter::addController

Add controller and route its' endpoints.

  • @param controller
  • @return - std::shared_ptr to the controller added.

std::shared_ptr<server::api::ApiController> addController(const std::shared_ptr<server::api::ApiController>& controller)