- Endpoint:
POST /auth/register
- Description: Register a new user.
- Body:
{ "email": "[email protected]", "password": "password123", "name": "John", "lastname": "Doe", "username": "johndoe" }
- Response: Successful user registration.
- Endpoint:
POST /auth/login
- Description: User login and token generation.
- Body:
{ "email": "[email protected]", "password": "password123" }
- Response: Returns
authToken
for authorization.
Where to Get the Token:
After a successful login, the response will include an authToken
. Copy this token to authenticate your requests.
Example Response:
{
"message": "Login successful",
"authToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}
- Endpoint:
POST /auth/logout
- Description: Log out the user (client-side token removal is required).
- Headers:
Authorization: Bearer <authToken>
- Endpoint:
POST /posts
- Description: Create a new post.
- Headers:
Authorization: Bearer <authToken>
- Body:
{ "title": "My First Post", "body": "This is the content of the post.", "description": "Short description here." }
- Response: Returns the created post.
- Endpoint:
GET /posts
- Description: Retrieve a list of all posts.
- No Authorization Required
- Endpoint:
PUT /posts/:id
- Description: Update a post (only the author can update).
- Headers:
Authorization: Bearer <authToken>
- Body:
{ "title": "Updated Title", "body": "Updated content." }
- Response: Confirmation of successful update.
- Endpoint:
POST /posts/:id/comments
- Description: Add a comment to a specific post.
- Headers:
Authorization: Bearer <authToken>
- Body:
{ "commentBody": "This is a comment." }
- Response: Confirmation of successful comment addition with the updated post.
- Endpoint:
POST /posts/:id/like
- Description: Add or remove a like for a specific post. A user can only like a post once. If the user has already liked the post, this will remove the like.
- Headers:
Authorization: Bearer <authToken>
- Response:
or
{ "message": "Like added.", "likes": 10 }
{ "message": "Like removed.", "likes": 9 }
- Endpoint:
GET /users/:id
- Description: Retrieve user information.
- No Authorization Required
- Endpoint:
PUT /users/:id
- Description: Update user information.
- Headers:
Authorization: Bearer <authToken>
- Body:
{ "name": "Updated Name", "lastname": "Updated Lastname" }
- Response: Confirmation of successful update.
- Endpoint:
DELETE /users/:id
- Description: Delete a user account.
- Headers:
Authorization: Bearer <authToken>
- Response: Confirmation of successful deletion.
- Endpoint:
PUT /users/:id/follow
- Description: Follow another user.
- Headers:
Authorization: Bearer <authToken>
- Body:
{ "_id": "<your_user_id>" }
- Endpoint:
PUT /users/:id/unfollow
- Description: Unfollow a user.
- Headers:
Authorization: Bearer <authToken>
- Body:
{ "_id": "<your_user_id>" }
- Log in via
POST /auth/login
and copy theauthToken
from the response. - In Postman, go to the Authorization tab.
- Select Bearer Token as the type.
- Paste the token into the field and send the request.
When is the Token Required?
The token is required for all protected routes (creating posts, updating user data, following users, etc.). For public information (like viewing posts), no token is needed.