Skip to content

enrique-pastrana/data-server-sample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

server.js Overview

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.

Endpoints

  • Products:

    • GET /products — List all products
    • GET /products/:id — Get product by ID
    • POST /products — Add a new product
    • PUT /products/:id — Update product by ID
    • DELETE /products/:id — Delete product by ID
  • Albums:

    • GET /albums — List all albums
    • GET /albums/:id — Get album by ID
    • POST /albums — Add a new album
    • PUT /albums/:id — Update album by ID
    • DELETE /albums/:id — Delete album by ID

How to Run with Docker Compose

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.


Example Usage

Add a Product

curl -X POST http://localhost:3000/products \
  -H "Content-Type: application/json" \
  -d '{"name":"Keyboard","price":45,"stock":20}'

List All Products

curl http://localhost:3000/products

Update a Product

curl -X PUT http://localhost:3000/products/1 \
  -H "Content-Type: application/json" \
  -d '{"price":1100,"stock":8}'

Delete a Product

curl -X DELETE http://localhost:3000/products/2

Add an Album

curl -X POST http://localhost:3000/albums \
  -H "Content-Type: application/json" \
  -d '{"artist":"Daft Punk","title":"Discovery","format":"CD"}'

List All Albums

curl http://localhost:3000/albums

Update an Album

curl -X PUT http://localhost:3000/albums/1 \
  -H "Content-Type: application/json" \
  -d '{"format":"Cassette"}'

Delete an Album

curl -X DELETE http://localhost:3000/albums/2

About

Simple CRUD server for testing purposes

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published