title: Parse REST query in C++
body: <p>I'd like to expose a REST API on my application, using the <a href="http://code.google.com/p/mongoose/">Mongoose</a> web server and providing handlers for different queries. </p>
  
  <p>An example of query would be like this (I'm only using GET for the moment, the rest of HTTP verbs will come later):</p>
  
  <pre><code>GET /items -&gt; returns a list of all items in JSON
  GET /item/by/handle/123456789 -&gt; returns item that has handle 123456789
  GET /item/by/name/My%20Item -&gt; returns item(s) that have the name "My Item"
  </code></pre>
  
  <p>What I'm curious is how I should implement the parsing of these queries. I can easily parse the first, since it is simply a matter of <code>if( query.getURI() == "/items") return ...</code>.<br>
  But for the next two queries, I have to manipulate <code>std::</code> strings in a whole different way, using some <code>std::string::find()</code> magic and offsets to get to the argument.   </p>
  
  <p>As an example, this is the implementation I have for the second query:</p>
  
  <pre><code>size_t position = std::string::npos;
  std::string path = "/item/by/handle/";
  
  if( (position = query.getURI().find(path) ) != std::string::npos )
  {
      std::string argument = query.getURI().substr( position + path.size() );
      // now parse the argument to an integer, find the item and return it
  }
  </code></pre>
  
  <p>What if I want to "templatize" this; meaning: I describe the path and the arguments I expect afterwards (an integer, a string, ....); and the code is automatically generated to handle this?</p>
  
  <p>Tl;Dr: I want to be able to handle REST queries in C++ with something along these lines:</p>
  
  <pre><code>registerHandler( "/item/by/handle/[INTEGER]", myHandlerMethod( int ));
  </code></pre>
  
  <p>Is this possible?</p>