The API will allow users to perform CRUD operations (Create, Read, Update, and Delete) on tasks
This document outlines the API endpoints for a Task Manager Application.
All URLs listed in this documentation are relative to the application's base URL. The base URL is dependent on the environment.
This endpoint returns all the tasks.
completed
: Optional. Filter the tasks based on their completion status. Valid values aretrue
andfalse
.priority
: Optional. Filter the tasks based on their priority level. Valid values arelow
,medium
, andhigh
.sortBy
: Optional. Sort the tasks by a specific property. Valid values arecreatedAt
. By default, the tasks are sorted by theircreatedAt
property in descending order.
Status code: 200 OK
{
"status": "success",
"message": "Tasks retrieved successfully",
"data": [
{
"id": 1,
"title": "Task 1",
"description": "Task 1 description",
"priority": "medium",
"completed": false,
"createdAt": "2023-04-22T12:00:00.000Z"
},
{
"id": 2,
"title": "Task 2",
"description": "Task 2 description",
"priority": "high",
"completed": false,
"createdAt": "2023-04-21T12:00:00.000Z"
}
]
}
Status code: 400 Bad Request
{
"status": "fail",
"message": "Invalid query parameter: sortBy"
}
This endpoint returns a single task based on the provided ID.
id
: The ID of the task to retrieve.
Status code: 200 OK
{
"status": "success",
"message": "Task retrieved successfully",
"data": {
"id": 1,
"title": "Task 1",
"description": "Task 1 description",
"priority": "medium",
"completed": false,
"createdAt": "2023-04-22T12:00:00.000Z"
}
}
Status code: 400 Bad Request
{
"status": "fail",
"message": "Invalid task ID"
}
This endpoint returns all tasks with the specified priority level.
level
: The priority level to filter tasks by. Valid values arelow
,medium
, andhigh
.
Status code: 200 OK
{
"status": "success",
"message": "Tasks retrieved successfully",
"data": [
{
"id": 1,
"title": "Task 1",
"description": "Task 1 description",
"priority": "medium",
"completed": false,
"createdAt": "2023-04-22T12:00:00.000Z"
},
{
"id": 2,
"title": "Task 2",
"description": "Task 2 description",
"priority": "medium",
"completed": false,
"createdAt": "2023-04-21T12:00:00.000Z"
}
}
Creates a new task.
POST /tasks
The request body must contain the following fields:
title
- The title of the task.description
- The description of the task.priority
- The priority level of the task (low, medium, or high).completed
- (Optional) Whether the task is completed or not. Defaults to false.
Status: 201 Created
{
"status": "success",
"message": "Created successfully",
"data": {
"id": 4,
"title": "Task 4",
"description": "Description of Task 4",
"priority": "medium",
"completed": false,
"createdAt": "2023-04-25T12:00:00.000Z"
}
}
PUT /tasks/:id: Update an existing task by its ID.
Updates an existing task by its ID with new information provided in the request body. Returns the updated task object as a response.
URL Parameters
id
(required): The ID of the task to be updated.
Request Body
The request body should contain a JSON object with the following properties:
title
(string, required): The title of the task.description
(string, required): The description of the task.priority
(string, required): The priority level of the task, which can be one oflow
,medium
, orhigh
.completed
(boolean, optional): The completion status of the task.
Response
status
(string): The status of the response, which can be eithersuccess
orfail
.message
(string): A message explaining the status of the response.data
(object): The updated task object.
Example
Request:
PUT /tasks/1
{
"title": "Updated Task Title",
"description": "Updated Task Description",
"priority": "medium",
"completed": true
}
Response:
{
"status": "success",
"message": "Updated successfully",
"data": {
"id": 1,
"title": "Updated Task Title",
"description": "Updated Task Description",
"priority": "medium",
"completed": true,
"createdAt": "2023-04-22T12:00:00.000Z"
}
}
This endpoint deletes a task from the list of tasks based on its ID.
-
URL
DELETE /tasks/:id
-
Parameters
id
: The ID of the task to be deleted (integer)
-
Example
DELETE /tasks/1
-
Status Codes
200 OK
: The task was successfully deleted.400 Bad Request
: Theid
parameter is not a valid integer or there is no task with the specifiedid
.
-
Example
{ "status": "success", "message": "Task successfully deleted" }
{ "status": "fail", "message": "Invalid id" }