Skip to main content

Endpoint

POST
/tasks
Creates a new task with the provided data

Request

Request Body

name
string
required
The name of the task. Must be between 1 and 500 characters.
done
boolean
required
Whether the task is completed. Defaults to false if not provided.

Example Request

curl -X POST http://localhost:9999/tasks \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Implement user authentication",
    "done": false
  }'

Response

task
object
The created task object

Status Codes

200
OK
Successfully created the task
422
Unprocessable Entity
Validation error - invalid request body

Example Responses

{
  "id": 3,
  "name": "Implement user authentication",
  "done": false,
  "createdAt": "2024-03-15T16:45:00.000Z",
  "updatedAt": "2024-03-15T16:45:00.000Z"
}

Validation Rules

The request body is validated using the insertTasksSchema from src/db/schema.ts:23-34:
  • name: Required string, minimum 1 character, maximum 500 characters
  • done: Required boolean
  • id, createdAt, updatedAt: Automatically generated and cannot be provided in the request

Implementation Details

This endpoint is defined in src/routes/tasks/tasks.routes.ts:23-43 and implemented in src/routes/tasks/tasks.handlers.ts:18-22. The task is inserted into the database using Drizzle ORM and the created record (with auto-generated fields) is returned.

Build docs developers (and LLMs) love