Skip to content

A REST API for a simple task manager application

Notifications You must be signed in to change notification settings

chinmaykunkikar/task-manager-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Task Manager API

Assignment 01

Problem Statement -- Build a RESTful API for a simple task manager application with the following endpoints

Endpoint Description
GET /tasks Retrieve all tasks.
GET /tasks/:id Retrieve a single task by its ID.
GET /tasks/priority/:level Retrieve tasks based on priority level. (Optional)
POST /tasks Create a new task.
PUT /tasks/:id Update an existing task by its ID.
DELETE /tasks/:id Delete a task by its ID.

Tasks

  • Use an in-memory data store (e.g., an array) to store the tasks.
  • Implement proper error handling for invalid requests.
  • Add input validation for task creation and updates. Validate that the title and description are not empty, and that the completion status is a boolean value.
  • Test the API using Postman or Curl to ensure it works as expected.
Optional Tasks
  • Implement filtering and sorting for the GET /tasks endpoint. For example, users should be able to filter tasks based on completion status and sort them by creation date.
  • Allow users to assign a priority level (e.g., low, medium, high) to each task. Update the API to support this new attribute in task creation, updates, and retrieval.
  • Implement an endpoint to retrieve tasks based on priority level: GET /tasks/priority/:level.

Schema

{
  "tasks": [
		{
		  "id": "string",
		  "title": "string",
		  "description": "string",
		  "completed": boolean,
		  "createdAt": Date.now() // a.k.a Unix epoch
		}
	]
}

Tests (using cURL)

(Use the data from tasks.json file)

  1. GET /tasks
curl --location "localhost:3000/tasks?completed=false&sort=1"
  1. GET /tasks/:id
curl --location "localhost:3000/tasks/5"
  1. GET /tasks/priority/:level
curl --location "localhost:3000/tasks/priority/high"
  1. POST /tasks
curl --location 'localhost:3000/tasks' \
--header 'Content-Type: application/json' \
--data '{
    "id": "99",
    "title": "Task 99",
    "description": "This is task 99",
    "completed": false
}'
  1. DELETE /tasks/:id
curl --location --request DELETE "localhost:3000/tasks/2"
  1. PUT /tasks/:id
curl --location --request PUT 'localhost:3000/tasks/2' \
--header 'Content-Type: application/json' \
--data '{
    "title": "Task 2",
    "description": "Task 2.5",
    "completed": true,
    "priority": "high"
  }'