Hi Pedro,
You can create multiple listeners to listen on multiple endpoints.
You can create multiple listeners to listen on multiple endpoints.
http_listener listenerVoices_1(L"http://localhost:8080/hello");
http_listener listenerVoices_1(L"http://localhost:8080/hello/helloagain");
listenerVoices_1.open().wait();
listenerVoices_1.support(web::http::methods::GET, [](web::http::http_request request)
{
request.reply(web::http::status_codes::OK, L"Hello world");
}
);
listenerVoices_2.open().wait();
listenerVoices_2.support( web::http::methods::GET, [](web::http::http_request request)
{
request.reply(web::http::status_codes::OK, L"Hello again world");
}
);
std::string line;
std::cout << "Press enter to exit" << std::endl;
std::getline(std::cin, line);
listenerVoices_1.close().wait();
listenerVoices_2.close().wait();
We consider a single listener can only listen on a single uri,, every listener will register on a shared http server and when the server receives requests, it will dispatch to the corresponding listener.