User Following API Documentation - bounswe/bounswe2025group8 GitHub Wiki
All endpoints require authentication:
Authorization: Token <user_token>
POST /api/users/{id}/follow/
Success (201):
{
"status": "success",
"message": "You are now following username."
}Errors: 400 (self-follow/duplicate), 401 (unauthorized), 404 (user not found)
POST /api/users/{id}/unfollow/
Success (200):
{
"status": "success",
"message": "You have unfollowed username."
}Errors: 400 (self-unfollow/not following), 401, 404
GET /api/users/{id}/
Success (200):
{
"id": 123,
"username": "john_doe",
"name": "John",
"surname": "Doe",
"profile_photo": "http://api/media/profile_photos/123/photo.jpg",
"followers_count": 42,
"following_count": 15,
"is_following": false,
...
}New fields: followers_count, following_count, is_following
GET /api/users/{id}/followers/?page=1
Success (200):
{
"count": 42,
"next": "http://api/users/123/followers/?page=2",
"previous": null,
"results": [
{
"id": 456,
"username": "jane_smith",
"name": "Jane",
"surname": "Smith",
"profile_photo": "http://api/media/profile_photos/456/photo.jpg",
"followed_at": "2025-12-07T10:30:00Z"
}
]
}GET /api/users/{id}/following/?page=1
Same response format as followers endpoint.
// Follow user
const followUser = async (userId, token) => {
const response = await fetch(`/api/users/${userId}/follow/`, {
method: 'POST',
headers: { 'Authorization': `Token ${token}` }
});
return response.json();
};
// Get followers
const getFollowers = async (userId, token, page = 1) => {
const response = await fetch(`/api/users/${userId}/followers/?page=${page}`, {
headers: { 'Authorization': `Token ${token}` }
});
return response.json();
};import axios from 'axios';
const followUser = (userId, token) =>
axios.post(`/api/users/${userId}/follow/`, {}, {
headers: { 'Authorization': `Token ${token}` }
});
const unfollowUser = (userId, token) =>
axios.post(`/api/users/${userId}/unfollow/`, {}, {
headers: { 'Authorization': `Token ${token}` }
});-
200- Success (GET, unfollow) -
201- Created (follow) -
400- Invalid request (self-follow, duplicate, not following) -
401- Unauthorized -
404- User not found