Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🌿 Express Product API Demo 🦄

Welcome to your simple & magical RESTful API built with Express.js!
Manage your product list stored in a JSON file — perfect for learning all those CRUD moves! 💃🕺


✨ Features

  • 📦 Get all products
  • 🔍 Get a product by ID
  • 🆕 Create a new product
  • 🔄 Update an existing product
  • Delete a product
  • 🚨 Validation with friendly error messages
  • 💾 Data saved in a local JSON file (data/products.json)
  • 🌐 CORS enabled for cross-origin requests ✨

🚀 Setup

  1. Clone the repo
git clone https://github.com/your-username/express-live-server-demo.git
cd express-live-server-demo
  1. Install dependencies
npm install
  1. Start the server
npm run dev

Server runs on 👉 http://localhost:3000

🔥 API Endpoints

📋 Get all products

GET /products

Returns an array of all products.

🔎 Get product by ID

GET /products/:id
  • id (number) - the product ID

Returns the product object or 404 if not found.

✨ Create a new product

POST /products
Content-Type: application/json

{
  "title": "Magic Mushroom Lamp",
  "price": 19.99,
  "description": "A glowing little friend for cozy nights."
}

Returns 201 Created with the new product or 400 on validation error.

🔄 Update a product

PUT /products/:id
Content-Type: application/json

{
  "title": "New title",         // optional
  "price": 15.00,               // optional
  "description": "New desc"     // optional
}

Returns 200 OK with updated product or 400/404 errors.

❌ Delete a product

DELETE /products/:id

Returns 200 OK with deletion confirmation or 404 if not found.

🚦 Validation Rules

  • 📃 title: required, must be a non-empty string
  • 💸 price: required, must be a finite positive number
  • 📄 description: required, must be a non-empty string

⚡ Testing with Thunder Client

Test all API endpoints with the included Thunder Client collection!

  • File: thunder_client/thunder-collection_ProductAPI.json
  • How to use:
  1. Open Thunder Client extension in VS Code
  2. Click Import
  3. Select the JSON file above
  4. Run requests and watch the magic happen! ✨

🌱 Future Improvements

  • 💾 Move to a real database (MongoDB, MySQL, etc.)
  • 🔐 Add authentication & authorization
  • 🛠️ Better error handling & logging

📜 License

MIT © Rainy

About

Express live server with validations and Thunder Client testing

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages