After pushing this project in your Local Environment Type this command "npm install" to install the required modules required for this assignment.
This API provides endpoints for user management and social interactions.
- restrictTouser: Middleware to restrict access to routes under "/user" to authenticated users.
- limiter: Middleware to limit access to the login endpoint to prevent brute force attacks.
- validate:
The validateInput
middleware is responsible for validating user input, particularly for the /signup
endpoint. It ensures that the provided username, password, and email meet certain criteria before creating a new user account.
-
Username: .
-
Must be at least 3 characters long.
-
Password:
- Must be at least 5 characters long.
- Must contain at least one uppercase letter, one lowercase letter, one number, and one special character.
-
Email:
- Must be a valid email address format.
The middleware checks the request body for the following fields:
username
(string, required): Username of the new user.password
(string, required): Password of the new user.email
(string, required): Email address of the new user.
If any of the input fields fail to meet the validation criteria, the middleware responds with a 400 Bad Request status code and an error message indicating the validation failure.
- Method: POST
- Path: /signup
- Description: Create a new user account.
- Middleware: validateInput
- Request Body:
username
(string, required): Username of the new user.password
(string, required): Password of the new user.
- Response:
- Status: 201 Created
- Body: Newly created user object
- Method: DELETE
- Path: /user/delete
- Description: Delete the authenticated user account.
- Middleware: restrictTouser
- Method: PUT
- Path: /user/follow/:username
- Description: Follow another user.
- Parameters:
username
(string, required): Username of the user to follow.
- Middleware: restrictTouser
- Method: PUT
- Path: /user/unfollow/:username
- Description: Unfollow another user.
- Parameters:
username
(string, required): Username of the user to unfollow.
- Middleware: restrictTouser
- Method: GET
- Path: /user/followerList
- Description: View the list of followers for the authenticated user.
- Middleware: restrictTouser
- Method: GET
- Path: /user/followingList
- Description: View the list of users followed by the authenticated user.
- Middleware: restrictTouser
- Method: PUT
- Path: /user/updateprofile
- Description: Update the profile information of the authenticated user.
- Middleware: restrictTouser
- Method: GET
- Path: /user/viewprofile
- Description: View the profile of a user.
- Parameters:
username
(string, required): Username of the user whose profile to view.
- Middleware: restrictTouser
- Method: GET
- Path: /user/mypost
- Description: View posts created by the authenticated user.
- Middleware: restrictTouser
- Method: PUT
- Path: /user/addpost
- Description: Add a new post for the authenticated user.
- Middleware: restrictTouser
- Method: PUT
- Path: /user/updatepost
- Description: Update a post created by the authenticated user.
- Middleware: restrictTouser
- Method: DELETE
- Path: /user/deletepost
- Description: Delete a post created by the authenticated user.
- Parameters:
postId
(string, required): ID of the post to delete.
- Middleware: restrictTouser
- Method: GET
- Path: /user/followingposts
- Description: View posts from users that the authenticated user is following.
- Middleware: restrictTouser
- Method: POST
- Path: /login
- Description: Authenticate and login a user.
- Middleware: limiter
- Request Body:
username
(string, required): Username of the user.password
(string, required): Password of the user.
- Response:
- Status: 200 OK
- Body: JWT token for authenticated user
- Method: POST
- Path: /logout
- Description: Logout the authenticated user.
- Middleware: restrictTouser