Endpoint
POST
/api/category
This endpoint requires authentication. Include a valid authorization token in the request.
Authentication
This endpoint is protected by theapi.auth middleware. You must include a valid authorization token in the request headers.
Request Body
The request body must contain ajson parameter with a JSON string containing the category data.
JSON string containing category data
The name of the category (required)
Validation Rules
name: Required field
Response
Returns a JSON object containing the created category or an error message.Success Response
HTTP status code (200 for success)
Response status (‘success’)
Error Response
HTTP status code (400 for validation error)
Response status (‘error’)
Error message describing what went wrong
Example Request
cURL
Example Responses
Success Response (200)
Validation Error (400)
Empty Request Error (400)
Implementation Details
This endpoint is defined inCategoryController.php:50. It:
- Receives data as a JSON string in the
jsonparameter - Validates that the
namefield is present (defined at line 58-60) - Creates a new Category model instance and saves it to the database
- Excludes
indexandshowmethods from authentication (middleware defined at line 16)
The request expects data to be sent as a form parameter named
json containing a JSON string, not as direct JSON in the request body.