REST API for a marketplace built with NestJS using TypeScript and PostgreSQL.
- Marketplace API demo
- Prerequisites
- Installation
- Running the Project
- Testing
- Project Structure
- Technologies Used
- API Endpoints
- Authentication & Authorization
- License
The following demo shows:
- application startup
- authentication flow
- protected endpoints
- basic CRUD operations
POST /authentication/sign-Up { "name": "TestName", "email": "user@mail.com", "password": "secret" }
POST /authentication/sign-In { "email": "user@mail.com", "password": "secret" }
{ "accessToken": "eyJhbGciOiJIUzI1NiIs...", "refreshToken": "eyJhbGciOiJIUzI1NiIs..." }
This project requires a running PostgreSQL database. The application will not start without a database connection.
docker-compose up -dClone the repository:
git clone https://github.com/Sany8k/marketplace_api.git
cd marketplace_apiInstall dependencies:
npm installCreate a .env file based on .env.example and configure database connection, JWT secret, and other variables.
Start in development mode:
npm install -g @nestjs/cli
nest start --watchor
npm run start:devBuild and run for production:
node dist/mainUnit tests are located next to the source files inside the src/ directory and are implemented using Jest and @nestjs/testing.
src/
βββ cart/ # Cart module
βββ categories/ # Categories module
βββ iam/ # Authentication and authorization (JWT)
βββ products/ # Products module
βββ users/ # Users module
βββ main.ts # Entry point
NestJS
TypeScript
PostgreSQL
TypeORM
JWT
Docker
Bcrypt
class-validator
Swagger
Users
| Method | Route | Description |
|---|---|---|
| GET | /users | Get all users |
| GET | /users/me | Get the authenticated user |
| PATCH | /users/:id | Update user as admin |
| PATCH | /users/me | Update the authenticated user |
| DELETE | /users/:id | Delete a user |
Authentication
| Method | Route | Description |
|---|---|---|
| POST | /authentication/sign-Up | Create a new account |
| POST | /authentication/sign-In | Login to an existing account |
| POST | /authentication/refresh-tokens | Refresh JWT token |
Products
| Method | Route | Description |
|---|---|---|
| GET | /products | Get all products |
| GET | /products/filter | Get products with query filters |
| GET | /products/:id | Get a product by ID |
| PATCH | /products/:id | Update a product by ID (admin) |
| POST | /products/create-product | Create a new product |
| POST | /products/wishlist/:id | Add product to wishlist |
| DELETE | /products/:id | Delete a product by ID |
| DELETE | /products/wishlist/:id | Remove product from wishlist |
Categories
| Method | Route | Description |
|---|---|---|
| GET | /categories | Get all categories |
| GET | /categories/:id | Get a category by ID |
| PATCH | /categories/:id | Update category as admin by ID |
| POST | /categories | Create a category (admin) |
| DELETE | /categories/:id | Delete a category (admin) |
Cart
| Method | Route | Description |
|---|---|---|
| GET | /cart | Get all products in cart |
| POST | /cart | Add product to cart |
| DELETE | /cart | Delete all products from cart |
| DELETE | /cart/:id | Delete a product by ID from cart |
For detailed API documentation, visit Swagger UI at: http://localhost:3000/api
JWT-based authentication
/authentication/sign-Up and /authentication/sign-In endpoints
Protected routes use AuthGuard and role-based checks
MIT License