This is a RESTful API for managing notes and tasks. Notes can have multiple associated tasks, and each task belongs to a specific note. The API provides endpoints to create, retrieve, update, and delete notes and tasks.
-
Install dependencies:
npm install
-
To initialize the database with fresh tables, run:
npm run db:reset
-
Start the server:
npm start
The server will start on http://localhost:3000 by default.
Endpoint: POST /notes
Request Body:
title
(string) - required: The title of the note.status
(string) - required: The status of the note. Allowed values are"urgent"
,"serious"
, and"unimportant"
.
Example Request:
{
"title": "My Note",
"status": "urgent"
}
Response:
-
200 OK
on success with the created note object:{ "id": 1, "title": "My Note", "status": "urgent", "nbTasks": 0 }
-
400 Bad
Request if:- title is missing.
- status is missing or not one of the allowed values.
Example Error Response:
{ "error": "The 'title' field is required." }
Endpoint: GET /notes/:id
Response:
-
200 OK
with the note object:{ "id": 1, "title": "My Note", "status": "urgent", "nbTasks": 2 }
-
404 Not Found
if the note does not exist.
Endpoint: GET /notes
Response:
-
200 OK
with an array of all note objects:[ { "id": 1, "title": "My Note", "status": "urgent", "nbTasks": 2 }, { "id": 2, "title": "Another Note", "status": "serious", "nbTasks": 0 } ]
Endpoint: DELETE /notes/:id
Response:
200 OK
if the note was deleted successfully.404 Not
Found if the note does not exist.
Endpoint: POST /notes/:id/tasks
Request Body:
content
(string) - required: The content of the task.
Example Request:
{
"content": "My Task Content"
}
Response:
-
200 OK
with the created task object:{ "id": 1, "content": "My Task Content", "noteId": 1 }
-
400 Bad Request
if content is missing. -
404 Not Found
if the note does not exist.
Endpoint: GET /notes/:id/tasks
Response:
-
200 OK
with an array of tasks for the specified note:[ { "id": 1, "content": "My Task Content" }, { "id": 2, "content": "Another Task" } ]
-
404 Not Found
if the note does not exist.
Endpoint: DELETE /tasks/:id
Response:
200 OK
if the task was deleted successfully.404 Not Found
if the task does not exist.
The server uses an SQLite database located in the same directory as the server file. To reset the database with pristine tables, use the following command:
npm run db:reset
This command deletes the current database file (if it exists) and creates a new one with empty notes and tasks tables.
The API returns 400 Bad Request
for validation errors, 404 Not Found
for missing resources, and 500 Internal Server Error
for unexpected server issues.
{
"error": "Invalid status. Allowed values are 'urgent', 'serious', or 'unimportant'."
}