Skip to main content

Add Reaction

Add a reaction to a post or comment. The backend uses api/Post/{postId}/reactions for posts and api/Comment/{commentId}/reactions for comments.

Endpoints

Post reaction

POST /api/Post/{postId}/reactions
Content-Type: application/json

Comment reaction

POST /api/Comment/{commentId}/reactions
Content-Type: application/json

Authentication: Required

Path Parameters

ParameterTypeRequiredDescription
postIdGUIDPostPost ID (for post reactions)
commentIdstringCommentComment ID (for comment reactions)

Request Body

{
"type": "like"
}

Parameters

ParameterTypeRequiredDescription
typestringYesReaction type: "like", "love", "haha", "dislike", "share"

Response

Success (200 OK)

{
"success": true,
"data": {
"id": "reaction-id",
"type": "like",
"userId": "user-id",
"targetId": "post-id",
"targetType": "post",
"createdAt": "2024-01-01T00:00:00Z"
}
}

Example

// React to post
const response = await fetch(`http://localhost:5000/api/Post/${postId}/reactions`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({ type: 'like' })
});

// React to comment
const response = await fetch(`http://localhost:5000/api/Comment/${commentId}/reactions`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({ type: 'love' })
});

Changing Reactions

If you already have a reaction, posting a new one will replace it:

// User has "like" reaction, change to "love"
POST /api/Post/{postId}/reactions
{ "type": "love" } // Replaces "like" with "love"

Reaction Types

  • like: 👍 Standard like reaction
  • love: ❤️ Show love and appreciation
  • haha: 😂 Find it funny or amusing
  • dislike: 👎 Express disagreement or dislike
  • share: 🔁 Share the content with others

Note: The view reaction type is used internally by the system to track views and cannot be manually added by users.

Next Steps