Quantcast
Channel: WE MOVED to github.com/microsoft/cpprestsdk. This site is not monitored!
Viewing all articles
Browse latest Browse all 4845

New Post: http_listener multiple routes

$
0
0
Hi Pedro,

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.

Viewing all articles
Browse latest Browse all 4845

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>