title: Rest Search Query handling special characters design standards
body: <p>I am designing a rest api where users can pass in queries using a search query language I will define.<br>
  The language will allow a number of operators eq, ne, gt, lt (equals, not equals, greater than, less than) etc etc. </p>
  
  <p>The language will allow grouping and logical operators AND and OR.  </p>
  
  <p>So for example a query about companies may look like the following</p>
  
  <p>/api/companies?q=(CompanyName eq Microsoft Or CompanyName eq Apple) And State eq California</p>
  
  <p>So this should give me all companies where company name equals 'Microsoft' or 'Apple' and the state is California.  </p>
  
  <p>So this all works fine except for the fact that the system that I am writing the api against is extremely flexible and allows almost any character to be inserted into fields values.  Additionally, I also must support custom fields and those are able to have special characters in the field name.  </p>
  
  <p>Initially my main concern was fields that contained parentheses.  I will be converting this query into a SQL server query and I need a way to ensure that I do not confuse a  parentheses in a field value with one that is intended for grouping.  My second thought was to force field values to be quoted, but I think this will also cause similar problems.  </p>
  
  <p>I was also considering that there may be a simple approach involving html encoding, but I am unable to see exactly how that would work. </p>
  
  <p>What I am looking for is any advice or examples of reasonable approaches to handle a rest search query with such flexible data. </p>