This is my To-Do API server following the Todo List API project on roadmap.sh.
Docker (Docker CLI and Docker Compose).
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
.
Register new user.
- Request body as JSON with properties
name
(username),email
andpassword
. - 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 as an existing user.
- Request body as JSON with properties
email
andpassword
. - 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.
Requires a bearer authentication.
Add new todo.
- Request body as JSON with properties
title
anddescription
. - Respond:
401 UNAUTHORIZED
if failed to authorize.201 CREATED
with the created todo as body, which has propertiesid
(new todo ID),title
anddescription
.500 INTERNAL SERVER ERROR
if other errors occur.
Update todo data by ID.
- Request parameters:
id
(Todo ID) - Request body as JSON with properties
title
anddescription
. - Respond:
403 FORBIDDEN
if failed to authorize.404 NOT FOUND
ifid
is invalid, i.e. not a number or not existing id.400 BAD REQUEST
iftitle
ordescription
is missing.200 OK
with updated todo if success.
Delete todo by ID.
- Request parameters:
id
(Todo ID) - Respond:
401 UNAUTHORIZED
if failed to authorize.404 NOT FOUND
ifid
if invalid.204 NO CONTENT
if success.
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
- 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.