This is a simple e-commerce API built with Express, TypeScript, MongoDB, Mongoose, and Zod.
- Node.js
- MongoDB
-
Clone the repository:
git clone https://github.com/ctafsiras/ecommerce-api.git cd ecommerce-api
-
Install dependencies:
npm install
-
Create a
.env
file in the root directory and add your MongoDB connection string:MONGO_URI=your_mongodb_connection_string PORT=3000
-
Start the server:
npm run dev
The server will start on http://localhost:3000
.
- Create Product:
POST /api/products
- Get All Products:
GET /api/products
- Get Product by ID:
GET /api/products/:productId
- Update Product:
PUT /api/products/:productId
- Delete Product:
DELETE /api/products/:productId
- Search Product:
GET /api/products?searchTerm=term
- Create Order:
POST /api/orders
- Get All Orders:
GET /api/orders
- Get Orders by Email:
GET /api/orders?email=user@example.com
This API uses Zod for validation. Make sure to provide data that adheres to the defined schemas.
The API provides meaningful error messages for validation and other errors.
- Insufficient Quantity Error
- Not Found Error
- Not Found Route