title: Building filter/query string for RESTful API
body: <p>I'm building RESTful API using Microsoft ASP.NET WebAPI. My problem concerns GET method, or more specifficaly, optimal solution for building query/filter strings in URL's.</p>
  
  <p>In my application, RESTful API acts just as proxy, or access point to my resources stored in database. It is meant to retrieve, insert, modify or delete records. The whole system stores only one type of entity, which is pretty complex, because it contains many various fields, lists and data in general. I'm using NoSQL for storing those entities, as there is pretty many of them.</p>
  
  <p>The problem lies in creating proper query string for retrieving those entities by <strong>specified criteria</strong>. Classic query string looks like this:</p>
  
  <pre><code>http://localhost/api/entities?field1=val1&amp;field2=val2&amp;field10=val3
  </code></pre>
  
  <p>What's wrong with this kind of query string is that it only allows to specify fields values by equality operator, and there is no place for logic operators between each field (&amp; is treated as somewhat AND operator).</p>
  
  <p>What I need, is to allow to specify more complex query strings, more like <strong>filters</strong>. I want to allow to tell system, that I want to get records, which have for instance:</p>
  
  <blockquote>
    <p>field1 >= value1 OR field2=value2 AND field3 ~ value3</p>
  </blockquote>
  
  <p>~ is indicates that i want to match field3 to value3 using FUZZY algorithm (although I'm not sure if ~ is proper character to indicate intention of using fuzzy search).</p>
  
  <p>Well, as you can see, classic query string is not capable of supporting that. For now, I'm passing such query string as:</p>
  
  <pre><code>http://localhost/api/entities?query=field1&gt;=value1$OR$field2=value2$AND$field3~value3
  </code></pre>
  
  <p>I pass such filter as one string to my controller's method and manually parse it. My delimiter is '$', as ASP.NET WebAPI would automatically split those parameters if there was '&amp;' character between them, and I don't want it to do that, because it is unable map logical operators (OR, AND, etc.) to method parameters in such case. I'm not sure if I'm doing the right thing by parsing this string (everything after '?' character) manually:</p>
  
  <pre><code>field1&gt;=value1$OR$field2=value2$AND$field3~value3
  </code></pre>
  
  <p>My question are:</p>
  
  <ol>
  <li>What is the proper way of representing such queries in RESTful API URLs?</li>
  <li>Is there any existing solution for supporting such filters in ASP.NET WebAPI, other than writing my own parsing algorithm?</li>
  </ol>