Skip to main content

Endpoint

DELETE /api/users/{username}

Authentication

This endpoint requires authentication using a JWT Bearer token.
Authorization: Bearer <token>

Path Parameters

username
string
required
The username of the user account to delete

Request Example

curl -X DELETE https://api.example.com/api/users/johndoe \
  -H "Authorization: Bearer <your_token>"

Response

Success Response

Status Code: 204 No Content The user account was successfully deleted. No response body is returned.

Error Responses

Status Code: 401 Unauthorized Returned when no valid JWT Bearer token is provided in the request. Status Code: 404 Not Found
"The user was not found"
The specified username does not exist in the system.
This is a Hard Delete OperationThis endpoint performs a permanent deletion of the user account. All user data will be removed from the database immediately. This action cannot be undone.Consider implementing a soft delete mechanism or data retention policy if you need to preserve user data or allow account recovery.

Implementation Details

From auth.endpoints.cs:99-107, the delete handler:
app.MapDelete("/api/users/{username}", async (string username, SocialMediaDataContext context) =>
{
    User? User = await context.Users.Where(u => u.UserName == username).FirstOrDefaultAsync();
    if (User is null) return Results.NotFound("The user was not found");

    context.Users.Remove(User);
    await context.SaveChangesAsync();
    return Results.NoContent();
}).RequireAuthorization();
The deletion process:
  1. Queries the database for the user by username
  2. Returns 404 Not Found if the user doesn’t exist
  3. Removes the user entity from the database context
  4. Saves changes to persist the deletion
  5. Returns 204 No Content on success
  • Update user - Modify user profile and account details

Build docs developers (and LLMs) love