HttpRouter.hpp

This File On Github
Ask A Question

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

HttpRouter

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

namespace oatpp { namespace web { namespace server { 
  class HttpRouter : public oatpp::base::Countable {}
}}}

Typedefs

Type Name Summary
oatpp::data::share::StringKeyLabel StringKeyLabel Convenience typedef for oatpp::data::share::StringKeyLabel.
oatpp::web::url::mapping::Router<std::shared_ptr<oatpp::web::protocol::http::incoming::Request>, std::shared_ptr<oatpp::web::protocol::http::outgoing::Response>> BranchRouter oatpp::web::url::mapping::Router of oatpp::web::protocol::http::incoming::Request and oatpp::web::protocol::http::outgoing::Response. Meaning router for Subscribers which accept incoming request as an input parameter and return outgoing request as an output parameter.
BranchRouter::UrlSubscriber Subscriber Subscriber which accept incoming request as an input parameter and return outgoing request as an output parameter. See HttpRouter::BranchRouter.
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] HttpRouter Constructor.
std::shared_ptr<HttpRouter> createShared Create shared HttpRouter.
void addSubscriber Add url pattern Subscriber (handler for all requests resolved by specified url-pattern).
BranchRouter::Route getRoute Resolve http method and path to oatpp::web::url::mapping::Router::Route
void logRouterMappings Print out all router mapping.

HttpRouter::StringKeyLabel

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

typedef oatpp::data::share::StringKeyLabel StringKeyLabel

HttpRouter::BranchRouter

oatpp::web::url::mapping::Router of oatpp::web::protocol::http::incoming::Request and oatpp::web::protocol::http::outgoing::Response. Meaning router for Subscribers which accept incoming request as an input parameter and return outgoing request as an output parameter.

typedef oatpp::web::url::mapping::Router<
  std::shared_ptr<oatpp::web::protocol::http::incoming::Request>,
  std::shared_ptr<oatpp::web::protocol::http::outgoing::Response>
> BranchRouter

HttpRouter::Subscriber

Subscriber which accept incoming request as an input parameter and return outgoing request as an output parameter. See HttpRouter::BranchRouter.

typedef BranchRouter::UrlSubscriber Subscriber

HttpRouter::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

HttpRouter::HttpRouter

Constructor.

HttpRouter()

HttpRouter::createShared

Create shared HttpRouter.

  • @return - std::shared_ptr to HttpRouter.

static std::shared_ptr<HttpRouter> createShared()

HttpRouter::addSubscriber

Add url pattern Subscriber (handler for all requests resolved by specified url-pattern).

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

void addSubscriber(const oatpp::String& method, const oatpp::String& urlPattern, const std::shared_ptr<Subscriber>& subscriber)

HttpRouter::getRoute

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

BranchRouter::Route getRoute(const StringKeyLabel& method, const StringKeyLabel& url)

HttpRouter::logRouterMappings

Print out all router mapping.

void logRouterMappings()