List All Products
curl -X GET http://localhost:8081/api/v1/inventory \
-H "Content-Type: application/json"
Retrieves a list of all products in the inventory system with their current stock levels.
GET /api/v1/inventory
Response
Unique product identifier (Stock Keeping Unit)
Detailed product description
Product price as a decimal value
Current available stock quantity (excludes reserved stock)
Response Example
[
{
"sku": "PROD-001",
"name": "Laptop Charger",
"description": "65W USB-C laptop charger compatible with most devices",
"price": 29.99,
"availableStock": 150
},
{
"sku": "PROD-002",
"name": "Wireless Mouse",
"description": "Ergonomic wireless mouse with 2.4GHz connectivity",
"price": 19.99,
"availableStock": 85
},
{
"sku": "PROD-003",
"name": "HDMI Cable",
"description": "6ft HDMI 2.1 cable supporting 4K@120Hz",
"price": 12.50,
"availableStock": 200
}
]
Get Product by ID
curl -X GET http://localhost:8081/api/v1/inventory/1 \
-H "Content-Type: application/json"
Retrieves detailed information for a specific product by its unique identifier.
GET /api/v1/inventory/{id}
Path Parameters
The unique identifier of the product to retrieve
Response
Unique product identifier (Stock Keeping Unit)
Detailed product description
Product price as a decimal value
Current available stock quantity (excludes reserved stock)
Response Example
Success (200)
Not Found (404)
{
"sku": "PROD-001",
"name": "Laptop Charger",
"description": "65W USB-C laptop charger compatible with most devices",
"price": 29.99,
"availableStock": 150
}
Returned when no product exists with the specified ID.
Create Product
curl -X POST http://localhost:8081/api/v1/inventory \
-H "Content-Type: application/json" \
-d '{
"sku": "PROD-004",
"name": "Mechanical Keyboard",
"description": "RGB mechanical keyboard with blue switches",
"price": 89.99,
"stock": 50
}'
Creates a new product in the inventory system with initial stock.
POST /api/v1/inventory
Request Body
Unique product identifier (Stock Keeping Unit). Must be unique across all products.
Product name. Cannot be blank.
Detailed product description. Optional.
Product price. Must be a decimal value greater than or equal to 0.0.
Initial stock quantity. Must be zero or positive.
Request Example
{
"sku": "PROD-004",
"name": "Mechanical Keyboard",
"description": "RGB mechanical keyboard with blue switches",
"price": 89.99,
"stock": 50
}
Response
The SKU of the created product
The name of the created product
The description of the created product
The price of the created product
The initial available stock quantity
Response Example
Created (201)
Bad Request (400)
{
"sku": "PROD-004",
"name": "Mechanical Keyboard",
"description": "RGB mechanical keyboard with blue switches",
"price": 89.99,
"availableStock": 50
}
The response includes a Location header with the URI of the created resource:Location: http://localhost:8081/api/v1/inventory/4
{
"timestamp": "2026-03-08T10:30:00.000+00:00",
"status": 400,
"error": "Bad Request",
"message": "Validation failed",
"errors": [
{
"field": "price",
"message": "must be greater than or equal to 0.0"
},
{
"field": "sku",
"message": "must not be blank"
}
]
}
Returned when validation fails for one or more fields.
Validation Rules
SKU
- Must not be blank
- Must be unique across all products
- Example:
"PROD-001", "LAPTOP-CHARGER-65W"
Name
- Must not be blank
- Should be descriptive and concise
- Example:
"Laptop Charger", "Wireless Mouse"
Description
- Optional field
- Can contain detailed product information
- Example:
"65W USB-C laptop charger compatible with most devices"
Price
- Must be greater than or equal to 0.0
- Stored as BigDecimal for precision
- Example:
29.99, 0.00, 199.99
Stock
- Must be zero or positive integer
- Represents initial available quantity
- Example:
0, 50, 1000
Implementation Notes
- The service uses Spring Boot validation annotations to ensure data integrity
- Product creation is an atomic operation - both product and stock records are created together
- The SKU field is case-sensitive
- Price values are handled as BigDecimal to prevent floating-point precision issues
- Upon successful creation (201), the response includes the
Location header pointing to the new resource