Skip to main content
Removes a like from a post. Uses a database transaction to ensure atomic operation.

Endpoint

DELETE /api/posts/{id}/like

Authentication

Required. User must be authenticated to unlike a post.

Path Parameters

id
integer
required
The unique identifier of the post to unlike (PostID)

Request Body

userName
string
required
The username of the authenticated user removing the like

Behavior

  • Uses a database transaction for atomic operation to ensure data consistency
  • Removes the PostLike record for the user and post
  • Decrements the post’s LikeCount
  • Transaction is rolled back if any operation fails

Request

curl -X DELETE https://api.example.com/api/posts/12345/like \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "userName": "johndoe"
  }'

Response

status
integer
204 No Content - Like removed successfully
204 No Content

Errors

404
error
Post or account does not exist, or action cannot be completed due to a block
409
error
The user has not liked the post
{
  "error": "The user has not liked post"
}

Build docs developers (and LLMs) love