You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This documentation provides detailed information about the API endpoints for the social media server. The API is designed for interaction with users, posts, followRequests, comments, likes, notifications, and messaging functionalities.
Base URL
Base URL:https://social-media-express-server.onrender.com
1. Authentication API
Endpoints:
1. Sign Up
URL:/api/auth/signup
Method:POST
Description: Registers a new user after validating input fields, ensuring the uniqueness of email and username. Passwords are hashed, a profile picture is generated, and a verification email is sent.
- **URL:** `api/auth/logout`
- **Method:** `POST`
- **Description:** Logs out the user.
- **Response:**
```json
{
"message": "Logged out successfully."
}
```
4. Verify Email
- **URL:** `/api/auth/verify-email`
- **Method:** `POST`
- **Description:** Verifies the user’s email using a verification code. Updates the user's verification status if valid; returns an error if invalid or expired.
---
Request Body Parameters
Parameter
Type
Description
Required
code
String
The verification token sent to the user's email
Yes
- **Response:**
- **Success:** User data including verification status.
- **Error:**
- "Invalid or expired verificationToken"
- "something went wrong in verification of user"
5. Forgot Password
- **URL:** `api/auth/forgot-password`
- **Method:** `POST`
- **Description:** Sends a password reset link to the user's email.
- **Request Body:**
```json
{
"email": "string"
}
```
- **Response:**
```json
{
"message": "Password reset link sent to email."
}
```
6. Reset Password
- **URL:** `api/auth/reset-password/:token`
- **Method:** `POST`
- **Description:** Resets the user's password using a reset token.
---
### Request Parameters
| Parameter | Type | Description | Required |
|-----------|--------|------------------------------------------|----------|
| `token` | String | The password reset token provided to the user | Yes |
### Request Body Parameters
| Parameter | Type | Description | Required |
|------------|--------|-----------------------------------------|----------|
| `password` | String | The new password for the user (8-15 characters) | Yes |
Description: Retrieves a list of users that the logged-in user does not follow.
Response:
[
{
"_id": "userId1",
"userName": "username1",
"email": "email1@example.com",
"profilePic": "URL to profile picture",
// other public fields...
},
{
"_id": "userId2",
"userName": "username2",
"email": "email2@example.com",
"profilePic": "URL to profile picture",
// other public fields...
}
// other suggested users...
]
2. Get User Profile
URL:/api/user/profile/{userName}
Method:GET
Description: This controller fetches a user's profile based on their userName. It distinguishes between the logged-in user and other users, returning appropriate profile information while ensuring that sensitive fields are excluded.
Response:
{
"userName": "exampleUser",
"email": "example@example.com",
"posts": [...],
"likedPosts": [...],
"savedPosts": [...],
// Other user details
}
3. Freeze Account
URL:/api/user/freeze
Method:PATCH
Description: Freezes the authenticated user’s account.
Response:
{
"message": "Account frozen successfully."
}
4. Update User
URL:/api/user/update/{id}
Method:PATCH
Authentication: Required
Description: Updates user profile information for the user with the given ID.
Request Body Parameters
Parameter
Type
Description
Required
userName
String
The new username for the user (if updating).
No
password
String
The new password for the user (if updating).
No
fullName
String
The full name of the user (if updating).
No
bio
String
A short biography of the user (if updating).
No
Response
{
"_id": "user_id",
"userName": "newUserName",
"fullName": "New Full Name",
"bio": "Updated bio",
"posts": [...],
"likedPosts": [...],
"savedPosts": [...],
// Other user details
}
5. Unfollow User
URL:/api/user/unfollow/{id}
Method:POST
Authentication: Required
Description: Unfollows the user with the specified ID.
Response:
{
"message": "User unfollowed successfully",
"user": {
"_id": "user_id",
"userName": "updatedUserName",
"fullName": "Updated Full Name",
"bio": "Updated bio",
"followings": [...],
"followers": [...],
// Other user details
}
}
3. Posts API
Endpoints:
1. Get Feed Posts
URL:/api/post/feed
Method:GET
Description: Retrieves all posts made by the current user and their followers.
Description: Marks all notifications as read for the authenticated user.
Response:
{
"message": "All notifications marked as read."
}
3. Delete All Notifications
URL:/api/notification
Method:DELETE
Description: Deletes all notifications for the authenticated user.
Response:
{
"message": "All notifications deleted successfully."
}
6. Chat API
Endpoints:
1. Send Message
URL:/api/chat/message
Method:POST
Description: Sends a message from one user to another. If there is no existing conversation between the sender and receiver, a new conversation is created.
Request Body Parameters
Parameter
Type
Description
Required
message
String
The message content, trimmed
Yes
recieverId
String
The ID of the user receiving the message
Yes
img
String
(Optional) Image Buffer to be sent with the message