Skip to main content
DELETE
/
users
/
{id}
curl -X DELETE https://api.library.com/users/1 \
  -u username:password
{
  "204": {},
  "401": {},
  "404": {}
}

Authentication

This endpoint requires HTTP Basic Authentication.

Path Parameters

id
long
required
The unique identifier of the user to delete

Response

This endpoint returns no content on successful deletion.
Deleting a user is a permanent operation and cannot be undone. Ensure you have proper authorization before deleting user accounts.

Status Codes

204
No Content
User successfully deleted. No response body is returned.
401
Unauthorized
Missing or invalid authentication credentials
404
Not Found
User with the specified ID does not exist (note: the controller implementation returns 204 even if the user doesn’t exist)
The current implementation returns 204 No Content regardless of whether the user exists. This is an idempotent operation - deleting a non-existent user is treated the same as successfully deleting an existing user.
curl -X DELETE https://api.library.com/users/1 \
  -u username:password

Considerations

Before deleting a user, consider the following:
  • Borrowed Books: If the user has active book rentals (borrowed books not yet returned), you may want to handle these first
  • Historical Records: Consider whether you need to preserve rental history for audit purposes
  • Cascade Behavior: Check your database configuration for how related rental records are handled (cascade delete, set null, etc.)

Best Practices

  1. Verify User Exists: Check that the user exists before attempting deletion
  2. Check for Active Rentals: Query the user’s borrowed books to ensure no active rentals
  3. Soft Delete Alternative: Consider implementing a soft delete (marking users as inactive) instead of hard deletion for better data integrity and audit trails
  4. Authorization: Ensure proper role-based access control is in place for delete operations

Build docs developers (and LLMs) love