C++ & libuv & uvw (C++ libuv wrapper library) 으로 http server을 구현했습니다.
Spring-boot의 RequestMapping과 같은 기능을 구현해놓아서 URL에 대한 접근이 용이합니다.
#include <iostream>
#include <uvw/loop.hpp>
#include <jshttpserver/server.hpp>
#include <jshttpserver/http_request.hpp>
#pragma comment(lib, "libuv.lib")
int main() {
auto loop = uvw::Loop::getDefault();
std::shared_ptr<jshttpserver::Server> server(jshttpserver::Server::create(loop));
server->requestMapping(jshttpserver::METHOD_ALL, "/api/test", [](jshttpserver::HttpRequest &req, jshttpserver::HttpResponse &res) {
std::cout << "requestMapping FOUND :: /api/test" << std::endl;
std::cout << "\tsearch[ " << req.url_search << " ]" << std::endl;
});
server->requestMapping(jshttpserver::METHOD_ALL, "/api/test2/{v1}/{v2}", [](jshttpserver::HttpRequest &req, jshttpserver::HttpResponse &res) {
std::cout << "requestMapping FOUND :: /api/test2/{v1}/{v2}" << std::endl;
std::cout << "\tsearch[ " << req.url_search << " ]" << std::endl;
});
server->requestMapping(jshttpserver::METHOD_ALL, "/api/test3/{v3:.+}", [](jshttpserver::HttpRequest &req, jshttpserver::HttpResponse &res) {
std::cout << "requestMapping FOUND :: /api/test3/{v3:.+}" << std::endl;
std::cout << "\tsearch[ " << req.url_search << " ]" << std::endl;
});
server->documentRootMapping("/docs/", [](jshttpserver::HttpRequest &req, jshttpserver::HttpResponse &res) {
std::cout << "documentRootMapping FOUND :: /docs/ :: path = " << req.doc_path_name << std::endl;
std::cout << "\tpath_name[ " << req.doc_path_name << " ], search[ " << req.url_search << " ]" << std::endl;
});
server->documentRootMapping("/doxs", [](jshttpserver::HttpRequest &req, jshttpserver::HttpResponse &res) {
std::cout << "documentRootMapping FOUND :: /doxs :: path = " << req.doc_path_name << std::endl;
std::cout << "\tpath_name[ " << req.doc_path_name << " ], search[ " << req.url_search << " ]" << std::endl;
});
server->addListen(8887);
loop->run();
return 0;
}
https://github.com/jc-lab/jshttpserver-uvw.git
반응형
'내가만드는것_만든것 > 오픈소스' 카테고리의 다른 글
[jcu-dparm] ATA, NVME, SCSI Identify & Command 라이브러리. Windows & Linux 지원. (0) | 2020.08.11 |
---|---|
openssl CMake 프로젝트에 포함하기 (0) | 2019.10.12 |
JCP (JsCryptoProvider) C++에서 Java의 SecurityProvider같은거 (0) | 2019.07.22 |
AsymSecureFile (0) | 2019.07.12 |
c++ stomp 프로토콜 구현 (0) | 2019.07.08 |
댓글