Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

REST - HTTP DELETE - semantics - only delete descendants

In our project, a list of all books can be retrieved through REST:

GET http://server/api/books/

A specific book can be retrieved as following:

GET http://server/api/books/:id/

Deleting a specific book is easy:

DELETE http://server/api/books/:id/

Now, to my question: what should be the result of the following call:

DELETE http://server/api/books/

Obviously, all books are deleted. But should the resource books/ also be deleted? That is, after the request:

  1. should GET /books/ return 200 OK with an empty list? or
  2. should GET /books/ return 404 not found?

According to the specs, which says that the concrete URI will be gone afterwards, I'd go for the second option. However, this makes things complicated and unlogic, in my opinion. It makes more sense to have an empty list of books, instead of no books.

What do you think?

like image 767
Appelsien S. Avatar asked Nov 04 '22 18:11

Appelsien S.


1 Answers

If it makes you feel better, assume that the server has logic that recreates the books resource automatically after it has been deleted. :-)

I'd go for 200 OK and an empty list. If you really don't like that then create a new resource called /books/all

and do

DELETE /Books/all
like image 143
Darrel Miller Avatar answered Nov 09 '22 16:11

Darrel Miller