title: How to keep server running (cpprestsdk - casablanca)
body: <p>I am developing a REST api using Microsoft's cpprestsdk (aka casablanca) and I am having trouble keeping the server running when executing my code. </p>
  
  <p>See my main.cpp here:</p>
  
  <pre><code>int main() {
      cout &lt;&lt; "Starting Server" &lt;&lt; endl;
  
      TransactionController server;
      server.setEndpoint("http://0.0.0.0:4200/api");
      server.initHandlers();
  
      try {
          server.openServer();
          cout &lt;&lt; "Server listening at: " &lt;&lt; server.getEndpoint() &lt;&lt; endl;
  
          // figure out how to keep server running without this?
          while (true);
      }
      catch(exception &amp;e) {
          cout &lt;&lt; "--- ERROR DETECTED ---" &lt;&lt; endl;
          cout &lt;&lt; e.what() &lt;&lt; endl;
      }
  
  
      // this doesn't get reached bc of the while(true)
      server.closeServer();
  
      return 0;
  }
  </code></pre>
  
  <p>Additionally, for reference this is the implementation or the functions I have in my main.cpp: </p>
  
  <pre><code>pplx::task&lt;void&gt; TransactionController::openServer() {
      return listener.open();
  }
  
  pplx::task&lt;void&gt; TransactionController::closeServer() {
      return listener.close();
  }
  
  std::string TransactionController::getEndpoint() const{
      return listener.uri().to_string();
  }
  
  
  void TransactionController::initHandlers() {
      listener.support(methods::GET, bind(&amp;TransactionController::handleGet, this, std::placeholders::_1));
      listener.support(methods::POST, bind(&amp;TransactionController::handlePost, this, placeholders::_1));
  }
  
  void TransactionController::setEndpoint(const string&amp; value) {
      listener = http_listener(value);
  }
  </code></pre>
  
  <p>I have found a not ideal workaround of adding a </p>
  
  <pre><code>while(true);
  </code></pre>
  
  <p>to keep the server running until I manually halt execution.</p>
  
  <p>I would like to implement this feature in a more elegant way however. I have explored the documentation online but have not been able to find the right methodology.</p>
  
  <p>Any tips or pointers in the right direction would be greatly appreciated, as I have never worked with Casablanca before. Thank you for your time!</p>