Skip to main content

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 ADMIN role
  • JWT is validated at the API Gateway
  • Services rely on gateway-injected headers:
    • X-User-Email
    • X-User-Role

๐Ÿ›๏ธ Get All Products (Public)โ€‹

Fetch all active products with optional filters and pagination.

โžค Endpointโ€‹


GET /api/products

โžค Query Parameters (Optional)โ€‹

ParamDescription
pagePage number
sizePage size
categoryFilter by category
brandFilter 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โ€‹

StatusReason
404Product 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โ€‹

EventTopicDescription
PRODUCT_CREATEDproduct-eventsProduct added
PRODUCT_UPDATEDproduct-eventsProduct updated
PRODUCT_DELETEDproduct-eventsProduct soft-deleted
PRODUCT_STOCK_UPDATEDproduct-eventsInventory change

๐Ÿ›ก๏ธ Authorization Rules Summaryโ€‹

RoleAllowed Actions
PUBLICView products & categories
ADMINCreate, update, delete products

๐Ÿ”„ Request Flowโ€‹


โš ๏ธ Common Errorsโ€‹

StatusMeaning
400Invalid input
401Unauthorized
403Forbidden
404Product not found
409Conflict

๐Ÿ“Œ 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.