This project provides a set of RESTful APIs for managing users, posts, and comments. It allows users to create, view, and edit their profiles, create posts, retrieve posts, and comment on posts.
Purposefully, I have kept the .env file so that the setup becomes easy. Obviously,it will be gitignored in a real scenario
The base URL for all endpoints is: http://localhost:3000/
(📌 Before testing , replace the 'authToken' with the actual token received during login from the /api/login route and 'referralCode' with the actual code received from the /api/referral/generate route in the 'everything.test.js' file and always create a new user and his/her password,email)
(📌 The test of the /api/referral/expire route will not pass (return 400 bad request) if the referral link has not been used by 5 people or it hasnt been 5 days yet(I have set this))
( So in postman from the Authorization tab choose "Bearer Token" and paste the token which you received from login route)
Rate Limiting(Bonus): If any of the refrral links are hit 10 times in a row,it will display the message:
-
Endpoint:
/api/register
-
Method:
POST
-
Description: Register a new user by providing username, email, and password in the request body.
-
Request Body:
{ "username": "example_user", "email": "user@example.com", "password": "password123" (minimum length:6) }
- Endpoint:
/api/login
- Method: POST Description: Authenticate and log in a user. Provide email and password in the request body.
Request Body:
{
"email": "user@example.com",
"password": "password123"
}
Response: Returns a JWT token if successful for further authentication.
- Endpoint:
/api/balance
- Method:: GET Description: Retrieve user balance by user ID.
Authorization: Bearer Token (JWT)
{
"userId": "the respective mongodb _id of the user"
}
Response: User Balance if found.
- Endpoint:
/api/referral/generate
- Method: POST
Request Body:
In the Authorization tab in Bearer section ,paste the token of this user who is referring other 5 users
{
"userId": "the respective mongodb _id of the user"
}
- Endpoint:
/api/referral/expire
- Method: POST
Request Body:
In the Authorization tab in Bearer section ,paste the token of this user who is referring other 5 users
This can only be expired after 5 days (I have set this) or after the referral link has been used by 5 other people
{
"userId": "the respective mongodb _id of the user"
}
- Endpoint:
/api/referral/verify
- Method: POST
Request Body:
{
"code": "The code received from the /api/referral/generate endpoint"
}