Skip to main content

Endpoint

PATCH
/tasks/{id}
Updates specific fields of an existing task

Request

Path Parameters

id
number
required
The unique identifier of the task to update

Request Body

All fields are optional. Only provide the fields you want to update.
name
string
The new name for the task. Must be between 1 and 500 characters if provided.
done
boolean
The new completion status for the task

Example Request

curl -X PATCH http://localhost:9999/tasks/1 \
  -H "Content-Type: application/json" \
  -d '{
    "done": true
  }'

Response

task
object
The updated task object with all fields

Status Codes

200
OK
Successfully updated the task
404
Not Found
Task with the specified ID does not exist
422
Unprocessable Entity
Validation error - invalid ID parameter or request body

Example Responses

{
  "id": 1,
  "name": "Complete project documentation",
  "done": true,
  "createdAt": "2024-03-15T10:30:00.000Z",
  "updatedAt": "2024-03-15T18:22:00.000Z"
}

Validation Rules

The request body is validated using the patchTasksSchema from src/db/schema.ts:37, which is a partial version of insertTasksSchema:
  • name: Optional string, but if provided must be between 1 and 500 characters
  • done: Optional boolean
  • At least one field must be provided (empty object returns 422 error)
  • id, createdAt, updatedAt: Cannot be modified

Implementation Details

This endpoint is defined in src/routes/tasks/tasks.routes.ts:68-94 and implemented in src/routes/tasks/tasks.handlers.ts:44-82. The endpoint performs a partial update, meaning you only need to send the fields you want to change. The updatedAt timestamp is automatically updated by the database on each modification.

Build docs developers (and LLMs) love