This project is a RESTful API built with Node.js and Express, focused on applying industry best practices, including:
- Semantic URIs (plural nouns)
- Proper HTTP methods
- Correct status codes
- Data validation
- Standardized responses
npm init -y
npm install express colors dotenvnode server.jsnode --watch server.jshttp://localhost:3000
Create a .env file in the root:
PORT=3000All requests must include:
Content-Type: application/json
products-api/
βββ utils/
β βββ response.js
βββ prints/
β βββ errors/
β β βββ DELETE-erro.png
β β βββ GET-404.png
β β βββ PATCH-erro.png
β β βββ POST-create-erro.png
β β βββ PUT-erro.png
β βββ logs/
β β βββ Logs.png
β βββ sucess/
β βββ DELETE-products.png
β βββ GET-product-id.png
β βββ GET-products.png
β βββ PATCH-product.png
β βββ POST-products.png
β βββ PUT-products.png
βββ server.js
βββ package.json
βββ README.md
| Method | Route | Description |
|---|---|---|
| GET | /products | List all products |
| GET | /products/{id} | Get product by ID |
| POST | /products | Create a new product |
| PUT | /products/{id} | Fully update a product |
| PATCH | /products/{id} | Partially update a product |
| DELETE | /products/{id} | Delete a product |
| GET | /health | API health check |
{
"name": "Laptop",
"price": 5000,
"stock": 10,
"category": "Electronics"
}{
"status": 200,
"type": "success",
"message": "Operation completed successfully",
"data": {}
}{
"status": 404,
"error": "Not Found",
"message": "Product not found"
}{
"status": 400,
"error": "Bad Request",
"message": "Name and price must be greater than zero"
}[
{
"id": 1,
"name": "Gaming Laptop",
"price": 7500,
"stock": 30,
"category": "Electronics"
}
]{
"status": 404,
"error": "Not Found",
"message": "Product not found"
}{
"status": 201,
"type": "success",
"message": "Product created successfully",
"data": {
"id": 3,
"name": "Mouse",
"price": 100,
"stock": 20,
"category": "Electronics"
}
}{
"status": 400,
"error": "Bad Request",
"message": "Name and price must be greater than zero"
}Tested scenarios using Postman:
- β GET /products β 200
- β GET /products/{id} β 404
- β POST valid β 201
- β POST invalid β 400
- β PUT β 200
- β PATCH β 200
- β DELETE β 204
All requests are logged in the terminal:
GET /products - 200 - 2ms
POST /products - 201 - 0ms
PUT /products/5 - 200 - 1ms
DELETE /products/5 - 200 - 1ms
PATCH /products/2 - 200 - 1ms
GET /aaaaaaa - 404 - 1ms
GET /health - 200 - 1ms
POST /products - 400 - 1ms
PUT /products/5 - 404 - 0ms
GET /products - 200 - 1ms
PUT /products/4 - 400 - 1ms
PUT /products/88 - 404 - 1ms
DELETE /products/78 - 404 - 0ms
Elyton Moreira







