This document details the REST API endpoints available in the CommerceX platform.
- Base URL:
http://localhost:8000(via API Gateway) or individual service ports. - Content-Type:
application/json - Rate Limit: 100 requests per 15 minutes per IP.
Port: 3001
Gateway Path: /users (proxies to root of User Service)
- Endpoint:
POST /auth/register - Description: Create a new user account.
- Payload:
{ "name": "Jane Doe", "email": "jane@example.com", "password": "strongpassword", "role": "customer" // optional, default: customer } - Response:
201 Created{ "_id": "65c...", "name": "Jane Doe", "email": "jane@example.com", "role": "customer", "token": "eyJhbG..." }
- Endpoint:
POST /auth/login - Description: Authenticate and receive a JWT.
- Payload:
{ "email": "jane@example.com", "password": "strongpassword" } - Response:
200 OK{ "_id": "65c...", "name": "Jane Doe", "email": "jane@example.com", "role": "customer", "token": "eyJhbG..." }
- Endpoint:
GET /users/profile - Headers:
Authorization: Bearer <TOKEN> - Response:
200 OK{ "_id": "65c...", "name": "Jane Doe", "email": "jane@example.com", "role": "customer" }
Port: 3002
- Endpoint:
POST /products - Payload:
{ "name": "MacBook Pro", "description": "M3 Chip", "price": 1999, "stock": 10, "category": "Laptops" } - Response:
201 Created
- Endpoint:
GET /products - Description: Retrieves products. Uses Read-Aside Caching (Redis).
- Response:
200 OK[ { "_id": "...", "name": "MacBook Pro", "price": 1999 } ]
Port: 3003
- Endpoint:
POST /orders - Payload:
{ "user": "<USER_ID>", "items": [ { "product": "<PRODUCT_ID>", "name": "MacBook Pro", "quantity": 1, "price": 1999 } ], "totalAmount": 1999 } - Description: Creates order with
PENDINGstatus and publishesorder-createdevent. - Response:
201 Created
All services expose a health check endpoint.
GET /health- Response:
{ "status": "UP", "service": "service-name", "db": "CONNECTED" // if applicable }