The Follow Requests API allows users to manage follow requests, including sending, accepting, rejecting follow requests, and fetching mutual followers between two users.
Note: Ensure that all API requests include a valid JSON Web Token (JWT) in the x-token
header to authenticate users.
Send a follow request to a user specified by :id
.
Request Headers:
x-token: <JWT>
Response:
{
"message": "Follow request sent successfully"
}
Retrieve the list of follow requests for the current user, with pagination support.
Request Headers:
x-token: <JWT>
Query Parameters:
page: <number> (optional, defaults to 1)
limit: <number> (optional, defaults to 5)
Response:
{
"followRequests": [
{
"_id": "userId",
"firstName": "John",
"lastName": "Doe",
"profileImage": "imageUrl",
"following": [...],
"followers": [...],
"followingCount": 10,
"followersCount": 8
}
],
"currentPage": 1,
"totalPages": 2,
"totalFollowRequests": 6,
"limit": 5
}
Accept a follow request from a user specified by :id
.
Request Headers:
x-token: <JWT>
Response:
{
"message": "Follow request accepted successfully"
}
Reject a follow request from a user specified by :id
.
Request Headers:
x-token: <JWT>
Response:
{
"message": "Follow request rejected successfully"
}
Retrieve mutual followers between the current user and another user specified by :id
.
Request Headers:
x-token: <JWT>
Response:
{
"mutualFollowers": [
{
"_id": "userId",
"firstName": "John",
"lastName": "Doe",
"profileImage": "imageUrl"
}
]
}
In case of errors, the API will return appropriate HTTP status codes and error messages. Common errors include 404 (User not found) and 500 (Server error). Handle these errors in the frontend to provide a smooth user experience.
Note: Ensure proper error handling in your application to manage scenarios like user not found, server errors, and unauthorized requests.