Description
This endpoint creates a new category in the system. The category name must be unique across all categories. Upon successful creation, the category is persisted to the database and returned with its generated ID.
Request Body
The name of the category. Must be unique across all categories in the system.
Optional. If not provided, the ID will be auto-generated by the database.
Response
Returns the created category object with its generated ID.
Auto-generated unique identifier for the category
The category name as provided in the request
HTTP Status Codes
Category successfully created and returned
Invalid request body or duplicate category name
An error occurred while processing the request
Example Request
curl -X POST http://localhost:8080/categories \
-H "Content-Type: application/json" \
-d '{
"name": "Sports Equipment"
}'
Example Response
Success (200 OK)
{
"id": 4,
"name": "Sports Equipment"
}
Error (400 Bad Request - Duplicate Name)
{
"timestamp": "2026-03-03T10:15:30.000+00:00",
"status": 400,
"error": "Bad Request",
"message": "Category name must be unique",
"path": "/categories"
}