Skip to main content
POST
/
categories
Create Category
curl --request POST \
  --url https://api.example.com/categories \
  --header 'Content-Type: application/json' \
  --data '
{
  "name": "<string>",
  "id": 123
}
'
{
  "200": {},
  "400": {},
  "500": {},
  "id": 123,
  "name": "<string>"
}

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

name
string
required
The name of the category. Must be unique across all categories in the system.
id
long
Optional. If not provided, the ID will be auto-generated by the database.

Response

Returns the created category object with its generated ID.
id
long
Auto-generated unique identifier for the category
name
string
The category name as provided in the request

HTTP Status Codes

200
OK
Category successfully created and returned
400
Bad Request
Invalid request body or duplicate category name
500
Internal Server Error
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"
}

Build docs developers (and LLMs) love