title: How to parse an URI elegantly in Casablanca
body: <p>How would one parse the URI of a request (server side) elegantly in C++?</p>
  
  <p>URI is defined as in the <a href="https://casablanca.codeplex.com/wikipage?title=URI" rel="noreferrer">Casablanca Documentation</a> as:</p>
  
  <blockquote>
    <p>protocol : // server [: port] / path ? query # fragment</p>
  </blockquote>
  
  <p>Lets say, i want the path (with all elements) as a list and the queries as a list of key/value pairs so</p>
  
  <blockquote>
    <p><a href="http://server/foo/bar?val1=1&amp;val2=yo" rel="noreferrer">http://server/foo/bar?val1=1&amp;val2=yo</a></p>
  </blockquote>
  
  <p>would result in</p>
  
  <pre><code>std::list&lt;string&gt; path;
  path.push_back("foo");
  path.push_back("bar");
  
  std::list&lt;std::pair&lt;string, string&gt;&gt; query;
  query.push_back(std::make_pair("val1", "1"));
  query.push_back(std::make_pair("val2", "yo"));
  </code></pre>
  
  <p>I want to avoid doing the parsing myself like proposed <a href="https://stackoverflow.com/questions/9148667/parse-rest-query-in-c">elsewhere</a>, mostly for portability and performance reasons.</p>
  
  <p><a href="http://cpp-netlib.org/0.10.1/in_depth/uri.html" rel="noreferrer">cpp-netlib</a> does not seem to be <a href="https://stackoverflow.com/questions/2616011/easy-way-to-parse-a-url-in-c-cross-platform">part of boost</a> yet and i'd prefer not to introduce a new library.</p>
  
  <p>Casablanca has an <a href="https://microsoft.github.io/cpprestsdk/classweb_1_1uri.html" rel="noreferrer">URI</a> object, but i cant find any parsing or iterators.</p>
  
  <p>Is there a way to solve this using only boost, c++, casablanca/cpprestsdk?</p>