Building a REST API was a good learning experience for me because it helped me understand how a backend application works and how different parts of an application communicate with each other. As part of my internship at Valentius Kryptix, I worked on a Task Management REST API using Node.js, Express.js and MongoDB.
The main purpose of this project was to create an API where users can register, log in and manage their own tasks. I focused on keeping the API simple, structured and secure while also handling different validation and error cases.
Technologies Used
For this project, I used Node.js as the runtime environment and Express.js to create the REST API and handle different routes. MongoDB was used as the database, and Mongoose was used to create models and interact with MongoDB.
I also used bcryptjs for password hashing and JSON Web Token (JWT) for authentication. dotenv was used for environment variables, and Postman was used to test the different API endpoints.
User Registration and Login
The first part of the project was user authentication. Users can create an account using their name, email and password.
Before saving the password in the database, I used bcryptjs to hash it. This means the actual password is not stored directly in the database. During login, the entered password is compared with the stored hashed password.
After successful login, the API generates a JWT token. This token is then used to access the protected task APIs.
JWT Authentication and Protected Routes
One of the important parts I learned from this project was how protected routes work.
The task routes cannot be accessed without a valid JWT token. The client needs to send the token in the Authorization header using the Bearer format.
The authentication middleware checks the token before allowing the request to reach the task controller. If the token is missing, invalid or expired, the API returns a 401 Unauthorized response.
This also helped me understand why authentication middleware is useful in backend applications.
Task CRUD Operations
The main resource in this project is a task. I implemented all the basic CRUD operations:
Create a new task
Get all tasks
Get a task by ID
Update a task
Delete a task
Each task contains a title, description and status. The available status values are pending, in-progress and completed.
Another important part is that tasks are connected to the user who created them. When a logged-in user requests their tasks, the API only returns tasks belonging to that user. The same user-based check is also applied when getting, updating or deleting a particular task.
Input Validation
I also added validation to the API so that incorrect data is not saved in the database.
For example, a task must have a valid title, and the status must be one of the allowed values. During registration, the API checks the name, email and password before creating the user.
The API also handles invalid task IDs and empty update requests. Different HTTP status codes are returned depending on the situation, such as 201 for successfully created data, 200 for successful requests, 400 for invalid input, 401 for authentication errors and 404 when a resource is not found.
Testing with Postman
After developing the API, I tested the endpoints using Postman. I tested user registration, login, protected routes, task creation, getting tasks, updating tasks and deleting tasks.
I also tested cases where the authentication token was missing or invalid and checked the validation responses for incorrect input.
What I Learned
Working on this project gave me a better understanding of backend development and REST APIs. I learned how to structure an Express.js project using routes, controllers, models and middleware.
I also understood authentication better, especially how passwords should be hashed and how JWT tokens can be used to protect API routes. Working with MongoDB and Mongoose gave me practical experience in storing and managing application data.
Overall, this project helped me connect the concepts I had learned with an actual backend application. It was a useful hands-on experience and improved my understanding of how a REST API is built, secured and tested.
Project:
https://github.com/madhaviporte/Valentius-Kryptix/tree/main/Task-APIs
Tagged in :
You May Love
-

Building a REST API with Node.js, Express and MongoDB
.
Building a REST API was a good learning experience for me because it helped me understand how a backend application works…
-
What is Machine learning? Regression from scratch
.
Machine learning (ML) is a branch of artificial intelligence that enables computers to learn from data, identify patterns, and make predictions…
-

Tuned Ensemble Pipeline – From Baseline Model to an Optimized Machine Learning Solution
.
Milestone: Tuned Ensemble Pipeline 🚀 Excited to share that I’ve completed the “Tuned Ensemble Pipeline” as part of my internship at…

Leave a Reply
You must be logged in to post a comment.