Security
What if somebody submits a SQL query like:
DELETE FROM comments
Oh, that's not good. We don't want to be able to delete all the comments. Maybe we'll have a list of approved SQL queries, like:
DELETE FROM comments WHERE id = ?;
Ok, but how do we know that comment belonged to the user? We need to add checks to make sure the user has permission to delete the comment. Maybe we also want to prevent deleting comments after five minutes or so.
This SQL api is getting more and more complicated. In fact, its becoming pretty much that REST api you were attempting to avoid creating. In order to make SQL queries work as an API, you are going to have to do all the work involved in a REST api. The only difference is that you have to deal with the complexities of incoming SQL.
Implementation Details
If you implement a REST api, you make promises about the internal implementations of anything. Comments could be stored in a table, or in a blob column on the post table, or in files, or in a NoSQL database. From the perspective of the API, it doesn't matter. By deliberately not giving access to the SQL, you prevent the frontend that uses the API from having to be rewritten if you make changes to how the comments are stored.
Altogether, trying to use SQL as an api won't be simpler than making a REST api. It will end up being much more complicated. And it will make it very hard to change the internal mechanisms of the API implementation.
POST
,HEAD
,OPTIONS
, or even the general notion of a "resource" into SQL? – Aaronaught Oct 5 at 15:05