Posts
Social network is all about posting what you are doing or what you are thinking. Following APIs are included in posts modules:
- Create post
- Update post
- Delete post
- Toggle like (like or un-like)
- Comment on post
- Fetch all posts
- Fetch single post
- Fetch people who liked the post
- Fetch people who commented on the post
- Fetch people who has shared the post
Create post
Creates a post on social media with logged-in user’s account. This API can also be used for sharing the post as well, you just need to pass the shared_post_id having the ID of post that is being shared.
You can also upload attachments with the post. The attachments must be image or video file. If the privacy of post is private, then the attachments will be saved in private storage. Otherwise, they will be saved in public storage.
URL = http://localhost:8000/api/posts/create
Method = POST
Headers
Accept | application/json |
Authorization | Bearer {access_token} |
Parameters
Key | Type | Required |
---|---|---|
caption | string | No |
type | string | No |
activity | string | No |
activity_value | string | No |
with_user | integer | 0 |
shared_post_id | integer | 0 |
time_zone | string | No |
- type: Define if the post is public or private. Possible values:
- private
- public
- activity: Tells if you are having any activity. Possible values:
- Eating
- Reading
- Feeling
- Playing
- Doing
- Going
- activity_value: Specify what you are doing. For example, if the activity is “Playing”, then activity_value can be “Cricket”.
- with_user: The ID of the user if you are going out with any of your friend.
- shared_post_id: If you are sharing a post, then this will be the ID of original post. It’s default value is 0.
Response
Status = 200
{
"status": "success",
"message": "Post has been created.",
"post": {
"id": 11,
"user_id": 2,
"caption": "Posting in private.",
"files": [
{
"path": "data:image/jpeg;base64,/9j/4AAQSkZJR...",
"size": 124782,
"type": "image/jpeg",
"extension": "JPG"
}
],
"type": "private",
"activity": "Playing",
"activity_value": "Cricket",
"likes": 0,
"comments": 0,
"shares": 0,
"shared_post_id": 0,
"created_at": "05 Oct, 2024 11:58:24 pm",
"updated_at": "05 Oct, 2024 11:58:24 pm"
}
}
- In “files” array, the key “path” will be absolute URL if the post is public. If the post is private, then it will be a base64 string.
Update post
Updates already uploaded post of user’s post. You can add more images or videos with the post if you want.
URL = http://localhost:8000/api/posts/update
Method = POST
Headers
Accept | application/json |
Authorization | Bearer {access_token} |
Parameters
Key | Type | Required |
---|---|---|
id | integer | Yes |
caption | string | No |
type | string | No |
activity | string | No |
activity_value | string | No |
with_user | integer | 0 |
shared_post_id | integer | 0 |
time_zone | string | No |
- id: The ID of the post that needs to be updated.
Response
Status = 200
{
"status": "success",
"message": "Post has been updated."
}
Delete post
Deletes the user’s post. All attached images and videos will be deleted as well.
URL = http://localhost:8000/api/posts/delete
Method = POST
Headers
Accept | application/json |
Authorization | Bearer {access_token} |
Parameters
Key | Type | Required |
---|---|---|
id | integer | Yes |
- id: The ID of the post that needs to be deleted.
Response
Status = 200
{
"status": "success",
"message": "Post has been deleted."
}
- This will also delete all the attached files with the post.
Toggle like (like or un-like)
Using this API, you can give reaction to a post. If you have already reacted to a post, then calling again this API will remove your reaction.
URL = http://localhost:8000/api/posts/toggle-like
Method = POST
Headers
Accept | application/json |
Authorization | Bearer {access_token} |
Parameters
Key | Type | Required |
---|---|---|
id | integer | Yes |
reaction | string | Yes |
- reaction: Defines how user has reacted to a post. Possible values:
- like
- love
- angry
- sad
- laugh
Response
Status = 200
{
"status": "success",
"message": "Post has been liked."
}
Comment on post
Lets you comment on a post. Your comment will be returned in fetch-comments API in upcoming sections.
URL = http://localhost:8000/api/posts/comment
Method = POST
Headers
Accept | application/json |
Authorization | Bearer {access_token} |
Parameters
Key | Type | Required |
---|---|---|
id | integer | Yes |
comment | string | Yes |
time_zone | string | No |
- id: The ID of the post.
Response
Status = 200
{
"status": "success",
"message": "Comment has been added.",
"comment": {
"id": 2,
"comment": "Nice post.",
"user_name": "Adnan Afzal",
"user_profile_image": "http://localhost:8000/storage/users/2/profile-IMG_0025.JPG",
"created_at": "05 Oct 2024, 11:16:25 pm"
}
}
Fetch all posts
Fetches all public posts uploaded on social network in descending order. So the latest uploaded posts will be on top.
URL = http://localhost:8000/api/posts
Method = POST
Headers
Accept | application/json |
Parameters
Key | Type | Required |
---|---|---|
page | integer | Yes |
Response
Status = 200
{
"status": "success",
"message": "Data has been fetched.",
"posts": [
{
"id": 16,
"caption": "Sharing post.",
"user_name": "Adnan Afzal",
"profile_image": "http://localhost:8000/storage/users/2/profile-IMG_0025.JPG",
"files": [
{
"path": "http://localhost:8000/storage/posts/2024-10-05/972971344568756318_n.jpg",
"size": 114529,
"type": "image/jpeg",
"extension": "jpg"
}
],
"type": "public",
"activity": "",
"with_user": 0,
"likes": 0,
"comments": 0,
"shares": 0,
"shared_post": {
"id": 15,
"caption": "Posting in private.",
"files": [
{
"path": "data:image/png;base64,iVBORw0KGgo...",
"size": 99584,
"type": "image/png",
"extension": "png"
}
],
"activity": ""
},
"created_at": "5 minutes"
}
]
}
- If the post is not shared, then the “shared_post” value will be null.
Fetch single post
Return single post if it is public. It will also return the attachments added to that post. If the post has shared another post, then the shared post will be returned as well.
URL = http://localhost:8000/api/posts/fetch
Method = POST
Headers
Accept | application/json |
Parameters
Key | Type | Required |
---|---|---|
id | integer | Yes |
time_zone | string | No |
Response
Status = 200
{
"status": "success",
"message": "Data has been fetched.",
"post": {
"id": 16,
"caption": "Sharing post.",
"user_name": "Adnan Afzal",
"profile_image": "http://localhost:8000/storage/users/2/profile-IMG_0025.JPG",
"files": [],
"type": "public",
"activity": "",
"with_user": 0,
"likes": 0,
"comments": 0,
"shares": 0,
"shared_post_id": 15,
"shared_caption": "Posting in private.",
"shared_files": [
{
"path": "data:image/png;base64,iVBORw0KGgoAAA...",
"size": 99584,
"type": "image/png",
"extension": "png"
}
],
"shared_activity": "",
"created_at": "29 minutes"
}
}
Fetch people who liked the post
If you want to get the list of all users who has reacted to a post, you can call this API. It will return the user name and profile image along with his reaction on that post.
URL = http://localhost:8000/api/posts/fetch-likes
Method = POST
Headers
Accept | application/json |
Parameters
Key | Type | Required |
---|---|---|
id | integer | Yes |
page | integer | Yes |
Response
Status = 200
{
"status": "success",
"message": "Data has been fetched.",
"likers": [
{
"id": 2,
"name": "Adnan Afzal",
"reaction": "sad",
"profile_image": "http://localhost:8000/storage/users/2/profile-IMG_0025.JPG"
}
]
}
Fetch people who commented on the post
Just like getting the users who has reacted to a post, using this API you can get a list of all users who has commented on a post. It will also return user name and profile image along with the comment he has posted.
URL = http://localhost:8000/api/posts/fetch-comments
Method = POST
Headers
Accept | application/json |
Parameters
Key | Type | Required |
---|---|---|
id | integer | Yes |
page | integer | Yes |
time_zone | string | No |
Response
Status = 200
{
"status": "success",
"message": "Data has been fetched.",
"comments": [
{
"id": 3,
"comment": "Nice post.",
"user_name": "Adnan Afzal",
"user_profile_image": "http://localhost:8000/storage/users/2/profile-IMG_0025.JPG",
"created_at": "05 Oct 2024, 11:29:49 pm"
}
]
}
Fetch people who has shared the post
Returns the posts that has shared a post. This will return the post shared when you call the posts/create API and pass the shared_post_id value other than 0.
URL = http://localhost:8000/api/posts/fetch-shares
Method = POST
Headers
Accept | application/json |
Parameters
Key | Type | Required |
---|---|---|
id | integer | Yes |
page | integer | Yes |
time_zone | string | No |
Response
Status = 200
{
"status": "success",
"message": "Data has been fetched.",
"posts": [
{
"id": 16,
"caption": "Sharing post.",
"user_id": 2,
"user_name": "Adnan Afzal",
"user_profile_image": "http://localhost:8000/storage/users/2/profile-1727853217-IMG_0025.JPG",
"created_at": "05 Oct, 2024 11:23:22 pm"
}
]
}