This script starts a simple Express.js REST API server for managing products and albums. Data is stored in memory (not persisted). You can create, read, update, and delete products and albums via HTTP requests.
-
Products:
GET /products
— List all productsGET /products/:id
— Get product by IDPOST /products
— Add a new productPUT /products/:id
— Update product by IDDELETE /products/:id
— Delete product by ID
-
Albums:
GET /albums
— List all albumsGET /albums/:id
— Get album by IDPOST /albums
— Add a new albumPUT /albums/:id
— Update album by IDDELETE /albums/:id
— Delete album by ID
This project includes a docker-compose-data-server-sample.yml
file to easily start the API server in a Docker container.
Start the server with Docker Compose:
docker compose -f docker-compose-data-server-sample.yml up --build
The server will be available at http://localhost:3000.
curl -X POST http://localhost:3000/products \
-H "Content-Type: application/json" \
-d '{"name":"Keyboard","price":45,"stock":20}'
curl http://localhost:3000/products
curl -X PUT http://localhost:3000/products/1 \
-H "Content-Type: application/json" \
-d '{"price":1100,"stock":8}'
curl -X DELETE http://localhost:3000/products/2
curl -X POST http://localhost:3000/albums \
-H "Content-Type: application/json" \
-d '{"artist":"Daft Punk","title":"Discovery","format":"CD"}'
curl http://localhost:3000/albums
curl -X PUT http://localhost:3000/albums/1 \
-H "Content-Type: application/json" \
-d '{"format":"Cassette"}'
curl -X DELETE http://localhost:3000/albums/2