Skip to content

A todo list api built using Express.js and TypeScript

Notifications You must be signed in to change notification settings

smallpaes/ts-todo-list-api

Repository files navigation

Todo List API

This is a backend project for a Todo List API built using express, express-validator, mysql2, typeorm, and typescript. The API provides three RESTful routes for managing tasks.

Run the server locally

The following instructions will get you a copy of the project and the setting needed to run the back-end server on your local machine.

Prerequisites

  1. Clone the repository:
git clone https://github.com/smallpaes/ts-todo-list-api.git
  1. Enter the project:
cd ts-todo-list-api
  1. Install the dependencies:
npm install
  1. Set up the database configuration in the .env file, which should contain the following variables(or reference to .env.example file):
PORT=
MYSQL_USER=
MYSQL_PASSWORD=
MYSQL_DB=
  1. Start the server:
npm start

Alternatively, you can run the server in development mode with:

npm run dev
  1. Find the message for successful activation:
App is listening on port 3000

Build the project

This project is built using Typescript. To compile it into Javascript, use the following command and the compiled files will be generated in the dist folder:

npm run build

RESTful Routes

GET /tasks

This endpoint returns all tasks from the database.

Response

[
  {
    "id": "8e31eb23-8e08-48b9-a2eb-8d0eb780dc3a",
    "title": "Task 2",
    "date": "2023-05-01T12:00:00Z",
    "description": "Description 2",
    "priority": "High",
    "status": "To Do"
  },
]

POST /tasks

This endpoint creates a new task in the database.

Request

{
  "title": "Task 2",
  "description": "Description 2",
  "date": "2023-05-01T12:00:00Z",
  "status": "Done",
  "priority": "High"
}

Response

{
  "title": "Task 2",
  "description": "Description 2",
  "date": "2023-05-01T12:00:00Z",
  "status": "To Do",
  "priority": "Done",
  "id": "8e31eb23-8e08-48b9-a2eb-8d0eb780dc3a"
}

PATCH /tasks/:id

This endpoint updates the status of a task in the database.

Request

{
  "status": "To Do"
}

Response

{
  "generatedMaps": [],
  "raw": [],
  "affected": 1
}