This document provides comprehensive information about the User Management API, a RESTful API built with NestJS that allows users to interact with a PostgreSQL database to manage user data.
Postman API Link:
https://elements.getpostman.com/redirect?entityId=21207467-79be0092-3cb6-4ff7-97f1-e41df12e3844&entityType=collection
- Features
- Technologies Used
- API Endpoints
- Error Handling
- Authentication and Authorization
- Testing
- Version Control
- CRUD Operations: Create, Read, Update, and Delete users.
- Authentication: Secure user authentication using JSON Web Tokens (JWTs).
- Authorization: Role-based authorization to restrict access to certain endpoints.
- Validation: Input validation to ensure data integrity.
- Error Handling: Robust error handling to provide informative error responses.
- NestJS: A progressive Node.js framework for building efficient and scalable server-side applications.
- Express.js: The underlying framework used by NestJS.
- PostgreSQL: A powerful open-source relational database.
- TypeORM: An Object-Relational Mapper (ORM) for TypeScript and JavaScript.
- JWT (JSON Web Tokens): An industry-standard method for representing claims securely between two parties.
- Git: A distributed version control system.
- GitHub: A web-based hosting service for Git repositories.
- Clone the repository:
git clone [repository url]
- Install dependencies:
npm install
- copy and paste the .env.sample to .env and setup the orginal values
- Set up the database:
- Create a PostgreSQL database.
- Update the database configuration in
src/app.module.ts
.
- Run the application:
npm run start
Endpoint: /users/ Method: POST
{
"email": "test@test.com",
"password": "password123"
}
Endpoint: /users/login Method: POST
{
"email": "test@test.com",
"password": "password123"
}
Endpoint: /users Method: GET Authorization: Requires a valid JWT. Response: 200 OK with an array of all users.
Endpoint: /users/:id Method: GET Authorization: Requires a valid JWT. Response: 200 OK with the user object. Error Handling: 404 Not Found if the user with the given ID is not found.
Endpoint: /users/:id Method: PUT Authorization: Requires a valid JWT. Request Body:
{
"email": "updateduser@example.com"
}
Endpoint: /users/:id Method: DELETE Authorization: Requires a valid JWT. Response: 200 OK with a success message. Error Handling: 404 Not Found if the user with the given ID is not found.
The API includes comprehensive unit tests using Jest to ensure that all endpoints and service methods function as expected. The tests cover various scenarios, including success cases, error handling, and validation.
Run the unit tests with: npm run test
Version control is handled using Git. To ensure code quality and organization:
Branches are used for new features and bug fixes. Commits follow the convention of meaningful messages. Pull requests are created for merging feature branches into the main branch.
- Added missing closing of code block tags for JSON payloads.
- Fixed inconsistencies in API endpoint descriptions (e.g., missing
/
in endpoint paths). - Adjusted response descriptions for clarity.
- Corrected the Table of Contents to reflect consistent section titles and links.
- Enhanced formatting for improved readability.