A small Express.js API with two routes:
| Method | Route | Description |
|---|---|---|
| GET | /products |
Returns the list of products |
| POST | /products |
Accepts JSON and adds a new product to the list |
Products are stored in memory, so the list resets when the server restarts.
npm install
npm startThe server runs at http://localhost:8080.
Import postman_collection.json into Postman, or create the requests by hand:
-
View the list: send a
GETrequest tohttp://localhost:8080/products. -
Add a product: send a
POSTrequest tohttp://localhost:8080/products. In the Body tab, choose raw and JSON, then enter:{ "name": "Mouse", "price": 49.99 }The response has status
201 Created:{ "message": "Product added", "product": { "id": 4, "name": "Mouse", "price": 49.99 } } -
Send the
GETrequest again. The new product is now in the list.
If name (a string) or price (a number) is missing, the API returns 400 Bad Request with an error message.