RESTful API with Express.js
What it does
This project demonstrates a simple RESTful API built using Express.js. It provides CRUD (Create, Read, Update, Delete) operations for managing user data. Users can retrieve all users, fetch a user by ID, add a new user, update an existing user, and delete a user by ID. The API handles requests in JSON format and responds with appropriate status codes and messages.
How we built it
Technology Stack:
- Node.js as the runtime environment.
- Express.js for building the server and handling routes.
- express.json() middleware for parsing incoming request bodies in JSON format.
Steps:
- Initialized a Node.js project using
npm init -y. - Installed dependencies:
express. - Created endpoints to perform CRUD operations on an in-memory array of users.
- Tested endpoints using Postman and curl to ensure correctness.
- Initialized a Node.js project using
Challenges we ran into
- Error Handling:
- Ensuring proper error messages and status codes were returned for invalid inputs or when a user was not found.
- Concurrency Issues:
- Handling potential conflicts when updating or deleting users in a real-world scenario where multiple requests might occur simultaneously.
- Designing Flexible Endpoints:
- Creating endpoints that could scale and adapt if the data structure or requirements changed.
Accomplishments that we're proud of
- Functionality:
- Successfully implemented all CRUD operations with clear and consistent API behavior.
- Code Simplicity:
- Maintained clean and readable code, making it beginner-friendly for others to learn from.
- Testing:
- Verified all endpoints to ensure they work as expected, handling both valid and invalid cases effectively.
What we learned
- Express.js Basics:
- Gained a deeper understanding of setting up a server and handling routes with Express.js.
- API Design Principles:
- Learned how to design RESTful APIs with proper status codes, error handling, and clear documentation.
- Importance of Testing:
- Understood the value of testing each endpoint thoroughly to ensure reliability and robustness.
Log in or sign up for Devpost to join the conversation.