A simple RESTful API built using Node.js, MongoDB, Express, and JWT for user authentication and post management(CRUD).
A simple RESTful API built using Node.js, MongoDB, Express, and JWT for user authentication and post management(CRUD).
- User registration (signup)
- User authentication (login)
- User logout
- Password reset functionality
- View & Update user profile
- Create Posts - (Create, Read, Update, Delete) Posts
- Add comments on posts
- Delete comments
- Swagger Documentation
Before you begin, ensure you have met the following requirements:
- Node.js installed
- MongoDB server running
- npm or yarn installed
- Clone the repository:
git clone https://github.com/MeetMulik/Rest-Api-Meet.git
- Install dependencies:
cd Rest-Api-Meet
npm install
- Set up environment variables: Create a .env file in the root of your project and add the following:
PORT=
MONGO_URI=
JWT_SECRET=
ADMIN_EMAIL=
ADMIN_PASSWORD=
1.To start the server, run the following command:
npm run dev
To view the Swagger documentation for the API, navigate to http://localhost:5000/api-docs/ after starting the application.
All post-related routes are prefixed with /api/users
.
- Method: POST
- Endpoint:
/signup
- Description: Registers a new user.
- Request Body:
{ "name": "", "username": "", "email": "", "password": "" }
- Response:
{ "_id": "", "name": "", "username": "", "email": "" }
- Method: POST
- Endpoint:
/login
- Description: Logs in an existing user.
- Request Body:
{
"username": "",
"password": ""
}
- Response: { "_id": "", "name": "", "username": "", "email": "" }
- Method: POST
- Endpoint:
/logout
- Description: Logs the user out.
- Method: POST
- Endpoint:
/forget-password
- Description: Initiates the password reset process.
- Request Body:
{ "email": "" }
- Response: (No specific response body; initiates the password reset process and sends an email with instructions)
- Method: POST
- Endpoint:
/reset-password
- Description: Resets the user's password.
- Request Body:
{ "password": "" }
- Response: (No specific response body; successful password reset)
- Method: GET
- Endpoint:
/profile/:username
- Description: Retrieves the profile information of a user by username.
- Method: PATCH
- Endpoint:
/profile/:id
- Description: Updates the profile information of a user by ID.
- Middleware:
protectRoute
- Request Body:
{ "username": "" } //Or any property to changed
All post-related routes are prefixed with /api/posts
.
- Method: GET
- Endpoint:
/
- Description: Retrieves all posts.
- Method: GET
- Endpoint:
/:postId
- Description: Retrieves a specific post by its ID.
- Method: GET
- Endpoint:
/user/:userId
- Description: Retrieves a specific post by its ID.
-
Method: POST
-
Endpoint:
/create
-
Description: Creates a new post.
-
Middleware:
protectRoute
-
Request Body:
{ "text": "", "postImg": "" }
-
Method: PATCH
-
Endpoint:
/update/:postId
-
Description: Updates an existing post.
-
Middleware:
protectRoute
-
Request Body:
{ "title": "", "content": "" }
- Method: DELETE
- Endpoint:
/:postId
- Description: Deletes a specific post.
- Middleware:
protectRoute
-
Method: POST
-
Endpoint:
/comment/:postId
-
Description: Adds a comment to a specific post.
-
Middleware:
protectRoute
-
Request Body:
{ "comment": "" }
- Method: DELETE
- Endpoint:
/:postId/comment/:commentId
- Description: Deletes a comment associated with a post.
- Middleware:
protectRoute