29 lines
888 B
C
29 lines
888 B
C
|
#pragma once
|
||
|
|
||
|
#include "Route.h"
|
||
|
|
||
|
#include <functional>
|
||
|
#include <vector>
|
||
|
|
||
|
namespace VWeb {
|
||
|
typedef std::function<bool(Request &, Response &)> RouteFunction;
|
||
|
class Router {
|
||
|
public:
|
||
|
Router();
|
||
|
void AddRoute(const std::string &name, const Ref<Route> &route);
|
||
|
Ref<Route> &GetRoute(const std::string &name);
|
||
|
void DeleteRoute(const std::string &name);
|
||
|
|
||
|
Ref<Response> HandleRoute(Ref<Request> &request);
|
||
|
Ref<Route> FindRoute(Ref<Request> &request);
|
||
|
static void AddToArgs(Ref<Request> &request, std::vector<std::string> &items);
|
||
|
|
||
|
public:
|
||
|
void Get(const std::string &path, RouteFunction);
|
||
|
void Post(const std::string &path, RouteFunction);
|
||
|
void Put(const std::string &path, RouteFunction);
|
||
|
void Patch(const std::string &path, RouteFunction);
|
||
|
void Delete(const std::string &path, RouteFunction);
|
||
|
std::unordered_map<std::string, Ref<Route>> m_Routes;
|
||
|
};
|
||
|
} // namespace VWeb
|