Skip to main content

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

Array
ProductReponseDto[]

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

id
long
required
The unique identifier of the product to retrieve

Response

sku
string
required
Unique product identifier (Stock Keeping Unit)
name
string
required
Product name
description
string
Detailed product description
price
number
required
Product price as a decimal value
availableStock
integer
required
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
}

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

sku
string
required
Unique product identifier (Stock Keeping Unit). Must be unique across all products.
name
string
required
Product name. Cannot be blank.
description
string
Detailed product description. Optional.
price
number
required
Product price. Must be a decimal value greater than or equal to 0.0.
stock
integer
required
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

sku
string
The SKU of the created product
name
string
The name of the created product
description
string
The description of the created product
price
number
The price of the created product
availableStock
integer
The initial available stock quantity

Response Example

{
  "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

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

Build docs developers (and LLMs) love