The HTTP status code returned by a DELETE API depends on the outcome of the operation. In RESTful applications, the most commonly used status code is 204 No Content when the resource is successfully deleted and no response body is returned. Other status codes may be used based on specific business requirements and API design.
Key Points: • 204 No Content is the most commonly recommended response for a successful deletion. • 200 OK can be returned when additional information is included in the response body. • 404 Not Found is typically returned when the resource does not exist. • The chosen status code should clearly communicate the result of the operation. • Consistent status code usage improves API usability and maintainability.
Common DELETE Response Status Codes
1. 204 No Content
Used when:
• Resource is successfully deleted. • No response body is required.
Code Example:
@DeleteMapping("/{id}")
public ResponseEntity<Void> deleteEmployee(
@PathVariable Long id) {
employeeService.delete(id);return ResponseEntity.noContent()
.build();
}Response:
HTTP/1.1 204 No Content
This is considered the preferred RESTful approach.
2. 200 OK
Used when:
• Resource is deleted successfully. • Additional information is returned.
Code Example:
@DeleteMapping("/{id}")
public ResponseEntity<String> deleteEmployee(
@PathVariable Long id) {
employeeService.delete(id);return ResponseEntity.ok(
"Employee deleted successfully");
}Response:
HTTP/1.1 200 OK
{ "message": "Employee deleted successfully" }
3. 404 Not Found
Used when:
• The requested resource does not exist.
Code Example:
@DeleteMapping("/{id}")
public ResponseEntity<String> deleteEmployee(
@PathVariable Long id) {
throw new EmployeeNotFoundException(
"Employee not found");
}Response:
HTTP/1.1 404 Not Found
{ "message": "Employee not found" }
4. 403 Forbidden
Used when:
• The user is authenticated but not authorized to delete the resource.
Response:
HTTP/1.1 403 Forbidden
5. 401 Unauthorized
Used when:
• Authentication is required before deletion.
Response:
HTTP/1.1 401 Unauthorized
How DELETE Request Processing Works
Client Sends DELETE Request | Resource Found? / \ Yes No | | Delete Resource Return 404 | Return 204 or 200
The status code should accurately represent the outcome of the operation.
Example: Suppose an Employee API exposes:
DELETE /employees/101
Scenario 1:
Employee exists.
Response:
204 No Content
Scenario 2:
Employee exists and confirmation message is returned.
Response:
200 OK
{ "message": "Employee deleted successfully" }
Scenario 3:
Employee does not exist.
Response:
404 Not Found
{ "message": "Employee not found" }
Best Practice
For REST APIs:
• Use 204 No Content for successful deletion when no response body is needed. • Use 200 OK when returning confirmation data. • Use 404 Not Found when the resource does not exist.
This follows standard REST conventions and keeps APIs predictable.
Interview Tip: A concise interview answer is:
"The most appropriate status code for a successful DELETE operation is 204 No Content when no response body is returned. If a confirmation message or additional information is included, 200 OK can be used. If the resource does not exist, 404 Not Found is typically returned."