Engineering Quiz #1 - RESTful APIs

Starting Engineering Quiz Section. I bring you a question related to Architecture, REST APIs, SOLID, anything that helps us reflect and debate!

The first one is about RESTful APIs 😄

Given a RESTful API and the sequence of Requests, which is the Status Code from the last call?

Some possible answers:

  1. OK. 200

  2. Bad Request. 400

  3. Not Found. 404

  4. Other

I will post the answer by Friday in the same Thread :D

For this scenario, the result can be either 200, as @Volodymyr shared, and 404, as Adrián Lizaga shared, because DELETE is an idempotent operation but the response can be different.

Check out the Wikipedia's article here

It states:

The GET, PUT, and DELETE methods are idempotent, meaning that applying them multiple times to resource results in the same state change of the resource as applying them once, though the response might differ

In case we are in a distributed system scenario, I prefer the 200 as a response code. Why? Because from the user's perspective, they want to delete an item. If for any reason the item is already deleted, it has the right response the system no longer contains that item.

Yet, if you compare the RESTful implementation to other Resource Containers such as Java Lists or SQL, you will find on them that, when you delete an item that doesn’t exist, the operation success and they don’t throw any exception.

So, why add the logic of failing to an operation when the other implementation doesn’t do and yet the final state is the desired state?