Note that there are some explanatory texts on larger screens.

plurals
  1. POAPI Design: Expressing search criteria in XML
    primarykey
    data
    text
    <p>Last year, my group developed a web service that included basic search functionality. All search conditions where combined with a boolean AND:</p> <pre><code>&lt;conditions&gt; &lt;condition name="name1"&gt;value1&lt;/condition&gt; &lt;condition name="name2"&gt;value2&lt;/condition&gt; &lt;conditions&gt; </code></pre> <p>... is equivalent to name1=value1 AND name2=value2 etc.</p> <p>Now, we have been asked to expand the search feature to allow for more complex searches. I see two plausible approaches:</p> <p><strong>OPTION #1: Let users pass in their own SQL query (either full clause, or just the 'where).</strong></p> <p>Examples:</p> <pre><code>&lt;where&gt;Cost = 5000.00 OR Cost &gt; 5000.00&lt;/where&gt; &lt;query&gt;SELECT cmis:name FROM cmis:document WHERE cmis:name LIKE '%test%'&lt;/query&gt; </code></pre> <p>Precedent:</p> <ul> <li><a href="http://publib.boulder.ibm.com/infocenter/p8docs/v5r0m0/index.jsp?topic=/com.ibm.p8.ce.dev.net.doc/M_FileNet_Api_Query_SearchSQL_SetWhereClause_1_bb3a7a4f.htm" rel="nofollow">SearchSQL.SetWhereClause</a> in IBM's FileNet API </li> <li><a href="http://docs.oasis-open.org/cmis/CMIS/v1.0/os/cmis-spec-v1.0.html#_Toc243905420" rel="nofollow">Content Management Interoperability Services (CMIS) spec</a></li> <li>ADO uses this approach in various places. For example, <a href="http://msdn.microsoft.com/en-us/library/ee275540%28v=bts.10%29.aspx" rel="nofollow">recordset.Filter</a></li> </ul> <p>Advantages:</p> <ul> <li>Our schema stays simple. We could leave the "&lt;conditions&gt;" approach in place for the simple use cases, and add an alternative syntax. </li> <li>We'd just use the WHERE clause directly server-side (after scrubbing for sql injection) == cleaner code server side</li> <li>Follows industry standards (does it? CMIS, Microsoft ... anything from the Java world?)</li> </ul> <p>Disadvantages:</p> <ul> <li>Not exactly "elegant xml" (is there any such thing?). Potentially forces consumers of the service to do some hackish string manipulation on their side, rather than providing them with something more elegant.</li> </ul> <p><strong>OPTION #2. Revamp our &lt;conditions&gt; approach to allow more granular queries in the soap request.</strong></p> <p>Example (from FetchXML):</p> <pre><code> &lt;filter type='and'&gt; &lt;condition attribute='lastname' operator='ne' value='Cannon' /&gt; &lt;/filter&gt; </code></pre> <p>Precedent:</p> <ul> <li><a href="http://msdn.microsoft.com/en-us/library/gg328117.aspx" rel="nofollow">FetchXML</a></li> <li><a href="http://ant-contrib.sourceforge.net/tasks/tasks/if.html" rel="nofollow">Ant gets close</a> with &lt;if&gt; / &lt;else&gt;</li> </ul> <p>Advantages:</p> <ul> <li>Arguably more consistent with what an end user would expect (often the mark of a good API)</li> <li>Potential to give end users cleaner code</li> <li>Doesn't create dependency on SQL language / backend. Keeps it abstract</li> </ul> <p>Disadvantages:</p> <ul> <li>More server-side code required to reconstruct the XML into the SQL statement the user meant in the first place</li> </ul> <p>I hope that the examples, precedent, advantages, and disadvantages give enough background to avoid subjective answers. I am looking for answers grounded in standards and best practices. </p> <p>My question is: are there definitive reasons for choosing one approach over the other in expanding an API?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload