uvco 0.1
Loading...
Searching...
No Matches
uvco::examples::Router Class Reference

#include <http_server.h>

Public Member Functions

void addRoute (const std::string &path, HttpHandler handler)
HttpHandler getHandler (const std::string &path) const

Private Attributes

std::unordered_map< std::string, HttpHandlerroutes_

Detailed Description

A simple HTTP router mapping paths to handlers. Supplied to the httpServer() function to dispatch requests to handlers.

Member Function Documentation

◆ addRoute()

void uvco::examples::Router::addRoute ( const std::string & path,
HttpHandler handler )
37 {
38 routes_[path] = std::move(handler);
39}
std::unordered_map< std::string, HttpHandler > routes_
Definition http_server.h:53

◆ getHandler()

HttpHandler uvco::examples::Router::getHandler ( const std::string & path) const
nodiscard
41 {
42 const auto it = routes_.find(path);
43 if (it != routes_.end()) {
44 return it->second;
45 }
46 return nullptr;
47}

Member Data Documentation

◆ routes_

std::unordered_map<std::string, HttpHandler> uvco::examples::Router::routes_
private

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