2024-06-16 13:17:24 +08:00
|
|
|
|
#ifndef WXHELPER_HTTP_ROUTER_H_
|
|
|
|
|
#define WXHELPER_HTTP_ROUTER_H_
|
|
|
|
|
#include <functional>
|
|
|
|
|
#include <unordered_map>
|
2024-08-05 07:23:50 +08:00
|
|
|
|
#include <string>
|
|
|
|
|
|
2024-06-16 13:17:24 +08:00
|
|
|
|
#include "singleton.h"
|
|
|
|
|
|
|
|
|
|
namespace http {
|
|
|
|
|
typedef std::function<std::string(std::string)> HttpHandler;
|
|
|
|
|
|
|
|
|
|
class HttpRouter : public base::Singleton<HttpRouter> {
|
|
|
|
|
public:
|
|
|
|
|
void HttpRouter::AddPathRouting(const std::string &path, HttpHandler handler);
|
|
|
|
|
|
|
|
|
|
std::string HandleHttpRequest(const std::string &path,
|
|
|
|
|
const std::string ¶m);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
std::unordered_map<std::string, HttpHandler> route_table_{};
|
|
|
|
|
};
|
|
|
|
|
} // namespace http
|
|
|
|
|
#endif
|