Skip to content

Build a CRUD API to allow users to manage their to-do list. Developed with Express and MySQL using Docker.

License

Notifications You must be signed in to change notification settings

hnthap/todo-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

To-Do API

docker mysql express typescript A Roadmap.sh project

This is my To-Do API server following the Todo List API project on roadmap.sh.

Requirements

Docker (Docker CLI and Docker Compose).

Setup

Add a file .docker.env with the content:

TOKEN_SECRET=<replace this with the actual secret key>

Then, add a file db.docker.env with the content:

MYSQL_HOST=db
MYSQL_DATABASE=todos
MYSQL_USER=<replace this with the actual username>
MYSQL_PASSWORD=<replace this with the actual password>
MYSQL_ROOT_PASSWORD=<replace this with the actual root password>
MYSQL_DATABASE=todos

Then run:

docker-compose up --build --detach

The server will serve at http://localhost:8000.

API Menu

Register

POST /register/

Register new user.

  • Request body as JSON with properties name (username), email and password.
  • Respond:
    • 400 BAD REQUEST if name or email or password is not provided, or is invalid.
    • 201 CREATED if success.
    • 500 INTERNAL SERVER ERROR if other errors occured.

Login

POST /login/

Login as an existing user.

  • Request body as JSON with properties email and password.
  • Respond:
    • 400 BAD REQUEST if email or password is not provided.
    • 401 UNAUTHORIZED if email or password is incorrect.
    • 200 CREATED with an authorization token if success.

Todos

Requires a bearer authentication.

POST /todos/

Add new todo.

  • Request body as JSON with properties title and description.
  • Respond:
    • 401 UNAUTHORIZED if failed to authorize.
    • 201 CREATED with the created todo as body, which has properties id (new todo ID), title and description.
    • 500 INTERNAL SERVER ERROR if other errors occur.

PUT /todos/:id

Update todo data by ID.

  • Request parameters: id (Todo ID)
  • Request body as JSON with properties title and description.
  • Respond:
    • 403 FORBIDDEN if failed to authorize.
    • 404 NOT FOUND if id is invalid, i.e. not a number or not existing id.
    • 400 BAD REQUEST if title or description is missing.
    • 200 OK with updated todo if success.

DELETE /todos/:id

Delete todo by ID.

  • Request parameters: id (Todo ID)
  • Respond:
    • 401 UNAUTHORIZED if failed to authorize.
    • 404 NOT FOUND if id if invalid.
    • 204 NO CONTENT if success.

GET /todos/

List todos.

  • Request query: page (page number), limit (number of todos per page).
  • Respond:
    • 401 UNAUTHORIZED if failed to authorize.
    • 200 OK with list of todos found.
  • Example: GET /todos/?page=1&limit=10

To-Dos

  • Handle errors related to SQL constraints
  • Add unit tests
  • Implement filtering and sorting for the to-do list
  • Implement rate limiting and throttling for the API
  • Implement refresh token mechanism for the authentication
  • Implement a simple static web client.

About

Build a CRUD API to allow users to manage their to-do list. Developed with Express and MySQL using Docker.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published