I'm creating a web API for an application and I have a DELETE
action for a resource. The resource is Names
, all of which are in a SQL Names
table. Each name has the foreign key of a Record
(all in a Records
table) and each Record
has a FileName
and IsValid
column.
This means that I can delete a bunch of Names
by FileName
, IsValid
, or a combination of these values. This is exactly what the application that will use the API requires.
However, in all the examples of API DELETE endpoints I've seen they are always deleting one record by its id
and it's making me doubt if my approach is not considered best practice.
This also brings up a question on how would I even do what I want to do? At the moment, my DELETE
endpoint for Names
is api/Names/{fileName}
and I'm not sure how to also include IsValid
into this. At least one or both FileName
and IsValid
values should be required. I do not want the user to be able to call api/Names
and delete every name in the database.
Delete action in NamesController:
[HttpDelete("{fileName}")]
public void DeleteBySourceFileName(string fileName)
{
_repo.DeleteNamesByFileName(sourceFileName);
}
I've thought about adding IsValid
as a query parameter in the action, but that would still keep fileName
required.
What would be the best approach to do this, and would such an endpoint be an appropriate for a RESTful API?