Product Service โ API Reference ๐ฆ
This document describes the public and admin APIs exposed by the Product Service in ShopVerse.
All APIs are accessed via the API Gateway.
Admin operations are protected using RBAC.
๐ Base URLโ
/api/products
๐ Authentication & Authorizationโ
- Public read APIs are accessible without authentication
- Admin mutation APIs require
ADMINrole - JWT is validated at the API Gateway
- Services rely on gateway-injected headers:
X-User-EmailX-User-Role
๐๏ธ Get All Products (Public)โ
Fetch all active products with optional filters and pagination.
โค Endpointโ
GET /api/products
โค Query Parameters (Optional)โ
| Param | Description |
|---|---|
page | Page number |
size | Page size |
category | Filter by category |
brand | Filter by brand |
โค Success Response (200 OK)โ
{
"content": [
{
"id": "PROD123",
"name": "Wireless Headphones",
"price": 2499,
"stock": 50,
"brand": "SoundX",
"category": "Electronics"
}
],
"totalElements": 120,
"totalPages": 12
}
๐ Get Product by ID (Public)โ
โค Endpointโ
GET /api/products/{productId}
โค Success Response (200 OK)โ
{
"id": "PROD123",
"name": "Wireless Headphones",
"description": "Noise cancelling",
"price": 2499,
"stock": 50,
"sku": "SNDX-001",
"brand": "SoundX",
"category": "Electronics"
}
โค Error Responsesโ
| Status | Reason |
|---|---|
| 404 | Product not found |
๐๏ธ Get Categories (Public)โ
โค Endpointโ
GET /api/categories
โค Success Response (200 OK)โ
[
{
"id": "CAT01",
"name": "Electronics"
},
{
"id": "CAT02",
"name": "Fashion"
}
]
โ Create Product (Admin)โ
Create a new product.
โค Endpointโ
POST /api/products
โค Role Requiredโ
ADMIN
โค Request Bodyโ
{
"name": "Bluetooth Speaker",
"description": "Portable speaker",
"price": 1999,
"stock": 100,
"brand": "BeatBox",
"categoryId": "CAT01"
}
โค Success Response (201 CREATED)โ
{
"message": "Product created successfully"
}
โ๏ธ Update Product (Admin)โ
โค Endpointโ
PUT /api/products/{productId}
โค Role Requiredโ
ADMIN
โค Request Bodyโ
{
"price": 1799,
"stock": 120
}
โค Success Response (200 OK)โ
{
"message": "Product updated successfully"
}
โ Delete Product (Admin โ Soft Delete)โ
Soft delete a product (marks inactive).
โค Endpointโ
DELETE /api/products/{productId}
โค Role Requiredโ
ADMIN
โค Success Response (204 NO CONTENT)โ
๐ฆ Bulk Product Creation (Admin)โ
Create multiple products in a single request.
โค Endpointโ
POST /api/products/bulk
โค Role Requiredโ
ADMIN
โค Request Bodyโ
[
{
"name": "Laptop Bag",
"price": 1499,
"stock": 40,
"brand": "CarryPro",
"categoryId": "CAT02"
}
]
โค Success Response (201 CREATED)โ
๐ก Events Publishedโ
| Event | Topic | Description |
|---|---|---|
| PRODUCT_CREATED | product-events | Product added |
| PRODUCT_UPDATED | product-events | Product updated |
| PRODUCT_DELETED | product-events | Product soft-deleted |
| PRODUCT_STOCK_UPDATED | product-events | Inventory change |
๐ก๏ธ Authorization Rules Summaryโ
| Role | Allowed Actions |
|---|---|
| PUBLIC | View products & categories |
| ADMIN | Create, update, delete products |
๐ Request Flowโ
โ ๏ธ Common Errorsโ
| Status | Meaning |
|---|---|
| 400 | Invalid input |
| 401 | Unauthorized |
| 403 | Forbidden |
| 404 | Product not found |
| 409 | Conflict |
๐ Summaryโ
The Product API provides:
- Public product discovery
- Secure admin-only product management
- Soft delete & inventory safety
- Event-driven extensibility
It forms the catalog backbone of the ShopVerse platform.