Rest API UPDATE/DELETE - check if resource exists or not?
<p>This is basically <em>best practice</em> question. In my Rest API (that I am currently working on) I have routes matching <code>PUT</code> and <code>DELETE</code> requests on URLs like <code>/resources/{resourceID}</code>. Behind the API lies SQL DB.</p>

<p>In general, executing a <code>DELETE</code> or <code>UPDATE</code> query on non-existing resource ID in SQL databases gives no error, only the <code>affectedRows</code> returns 0.</p>

<p>Now I have a question on how to perform such request properly:</p>

<ol>
<li>check if the resource with given ID exists prior to <code>UPDATE</code> or <code>DELETE</code> (which involves additional SQL query)</li>
<li>trigger the <code>UPDATE</code> / <code>DELETE</code> query without checking for existence and inspect the result of SQL query and return <code>HTTP 404</code> in case when <code>affectedRows == 0</code>?</li>
</ol>

<p>I personally prefer the later one. But I can think of other DBMS (not SQL or not relational) where performing <code>INSERT</code>, <code>UPDATE</code> or <code>DELETE</code> queries may not return any information about affected rows. How to proceed in such cases?</p>