Friends
In this section, we will cover how you can make friends in social network. We will have the following APIs for managing friends:
Send friend request
This API allows you to send a friend request to any user in the social network. Before sending the request, it will check if the friend request is not already sent or if the user is not your friend.
URL = http://localhost:8000/api/friends/send-request
Method = POST
Headers
Accept | application/json |
Authorization | Bearer {access_token} |
Parameters
Key | Type | Required |
---|---|---|
string | Yes |
- email: The email of user whom to send a friend request.
Response
Status = 200
{
"status": "success",
"message": "Friend request has been sent."
}
Remove friend request
Removes the friend request if the request is still in pending state.
URL = http://localhost:8000/api/friends/remove-request
Method = POST
Headers
Accept | application/json |
Authorization | Bearer {access_token} |
Parameters
Key | Type | Required |
---|---|---|
id | integer | Yes |
- id: The friend ID you wish to delete. You will get this ID in “Fetch all my friends” section.
Response
Status = 200
{
"status": "success",
"message": "Friend request has been deleted."
}
Accept or reject friend request
If someone sends you a friend request, you can accept or reject the friend request by calling this API. It only performs action if the friend request is still in pending state.
URL = http://localhost:8000/api/friends/action-request
Method = POST
Headers
Accept | application/json |
Authorization | Bearer {access_token} |
Parameters
Key | Type | Required |
---|---|---|
id | integer | Yes |
status | string | Yes |
- id: The friend ID you wish to perform action to. You will get this ID in next section.
- status: It’s value can be either “rejected” or “accepted”.
Response
Status = 200
{
"status": "success",
"message": "Friend request has been accepted."
}
Fetch all my friends
This will return an array of all your friends including the time when the friend request was accepted. So you will know for how long you 2 have been friends.
URL = http://localhost:8000/api/friends/my
Method = POST
Headers
Accept | application/json |
Authorization | Bearer {access_token} |
Parameters
Key | Type | Required |
---|---|---|
time_zone | string (e.g. Asia/Karachi) | No |
Response
Status = 200
{
"status": "success",
"message": "Data has been fetched.",
"friends": [
{
"id": 3,
"u1_name": "Adnan",
"u2_name": "Afzal",
"u1_profile_image": "http://localhost:8000/storage/users/2/profile-1727853217-IMG_0025.JPG",
"u2_profile_image": "http://localhost:8000/storage/users/2/profile-1727853217-IMG_0025.JPG",
"status": "accepted",
"accepted_at": "01 Oct, 2024 10:34:03 pm"
}
]
}