This project is an application developed in Node.js using the MongoDB database. The application allows users to be created with a username, email, and password. Once created, they can create posts.
- Node.js
- Express.js
- MongoDB
- Express-validator
- Mongoose
- JSON Web Tokens (JWT)
- Bcrypt.js
Authentication
- Middleware
- Added authentication to ensure that only authenticated users can create posts and perform other actions.
- Clone the repository to your local machine using the command
git clone https://github.com/abneribeiro/A64-API.git
- Navigate to the project directory using the command
cd directory-name
- Install project dependencies using the command
npm install
- Start the server using the command
node app.js
- The application will be available at
http://localhost:3000
- Use tools like Postman to test routes.
project-backend/
├── controllers/
│ ├── authController.js
│ ├── postController.js
├── middleware/
│ ├── authMiddleware.js
├── models/
│ ├── User.js
│ ├── Post.js
├── routes/
│ ├── authRoutes.js
│ ├── postRoutes.js
├── app.js
- Create Users
-
Endpoint:
POST /user/register
-
Description: Creates a new user with a name and password. The user's ID is automatically generated by the backend.
-
Parameters:
username
email
password
Response (JSON): Success (Status Code 201): Returns a success message along with information about the created post.
Error (Status Code 401 or 500): Returns an error message in case of issues.
- Login Users
- Endpoint:
POST /user/login
- Description: The user logs in by entering the name and password and generates a token.
- Parameters:
username
password
- User Profile Update
Authentication and Authorization
- Profile update routes are protected using a JWT token. Include the token in the Authorization header of each request to protected routes.
-
Endpoint:
PUT /users/profile
-
Description: The profile update functionality allows authenticated users to modify information such as their username, email and password. To access this feature, provide a valid JWT token obtained during login and must be included in the Authorization header of requests to protected routes. The server decodes the token to verify user authenticity. Provide the new data in the request body.
-
Parameters:
username
: New name of the user (optional).email
: New email of the user (optional).password
: New password of the user (optional).
-
Response (JSON):
-
Success (Status Code 200)
: Returns a success message along with the updated user information. -
Error (Status Code 401 or 500)
: Returns an error message in case of issues.
-
-
- Delete User
-
Endpoint:
DELETE /users/profile
-
Description: Deletes a specific user based on the provided token.
-
Response (JSON):
-
Success (Status Code 200)
: Returns a success message along with the deleted user information. -
Error (Status Code 401 or 500)
: Returns an error message in case of issues.
-
- Create Post
- Endpoint:
POST /posts/create
- Description: Creates a new post for a specific user based on the provided user token.
- Parameters:
title
: Post title.content
: Post content.
- Response (JSON):
_id
title
content
author
createdAt
- View All Posts
-
Endpoint:
GET /posts/all
-
Description: Returns a list of posts from a specific user based on the provided user token.
-
Response (JSON - Array):
_id
title
content
author
createdAt
- View Posts by User ID
- Endpoint:
GET /posts/:userId
- Description: Returns a list of posts from a specific user based on the provided user ID.
- Parameters:
userId
: ID of the user whose posts will be viewed.
- Response (JSON - Array):
id
: Post ID.userId
: ID of the user associated with the post.content
: Post content.createdAt
: Date and time of post creation.
- Delete Posts by User ID
- Endpoint:
DELETE /posts/:postId
- Description: Deletes a specific post based on the provided post ID.
- Parameters:
postId
: ID of the post to be deleted.
- Response (JSON):
message
: User post deleted
We appreciate your interest in contributing to our Open Source project! Your collaboration is crucial for the continuous improvement of our platform. If you're a dedicated programmer passionate about creating quality solutions, we're excited to welcome your contribution.
-
Fork the Repository: Begin by forking our GitHub repository. This will create a copy of the project in your own account.
-
Clone the Repository: Clone your forked repository to your local development environment.
-
Create a New Branch: Create a new branch for the work you intend to do. This helps keep development organized and enables discussion of proposed changes.
-
Implement Enhancements or Fixes: Make the necessary code changes. Ensure you follow our style guidelines and best programming practices.
-
Testing and Validation: Rigorously test your changes to ensure everything works as expected. Be sure to add new tests as well, when applicable.
-
Submit a Pull Request: Submit a Pull Request (PR) from your branch to the main branch of the original repository. Clearly describe the purpose of the PR and include any relevant context.
If you've discovered a bug or issue on our platform, we'd like to hear about it so we can address it promptly. When reporting a bug, follow these steps:
-
Search Before Reporting: Check if the bug has been reported previously in our issue tracking system. This helps to avoid duplications.
-
Create a New Issue: If the bug hasn't been reported, create a new issue on our GitHub repository. Provide clear details about the issue, including steps to reproduce it.
-
Include Context: If possible, provide additional information such as screenshots, error logs, and details about the environment in which the bug occurred.
We sincerely appreciate your contributions to our Open Source community. Our team will review your contributions and provide valuable feedback. Know that your time and effort are highly valued, and together, we can continue to enhance and strengthen our platform.
Thank you for joining us on this journey of development and continuous improvement!
Development Team
A64-Team