Skip to content

API Reference

ToDo

Bases: ToDoCreate

Schema for a to-do item, including a unique identifier.

Source code in backend/example.py
24
25
26
27
28
class ToDo(ToDoCreate):
    """
    Schema for a to-do item, including a unique identifier.
    """
    id: UUID

ToDoCreate

Bases: BaseModel

Schema for creating a new to-do item.

Source code in backend/example.py
16
17
18
19
20
21
22
class ToDoCreate(BaseModel):
    """
    Schema for creating a new to-do item.
    """
    title: str
    description: Optional[str] = None
    completed: bool = False

create_todo(todo)

Create a new to-do item.

Parameters:

Name Type Description Default
todo ToDoCreate

The to-do item to be created.

required

Returns:

Type Description

The newly created to-do item with a unique UUID.

Source code in backend/example.py
59
60
61
62
63
64
65
66
67
68
69
70
71
72
@app.post("/todos", response_model=ToDo, status_code=201, tags=["To-Dos"])
def create_todo(todo: ToDoCreate):
    """
    Create a new to-do item.

    Args:
        todo (ToDoCreate): The to-do item to be created.

    Returns:
        The newly created to-do item with a unique UUID.
    """
    new_todo = ToDo(id=uuid4(), **todo.dict())
    todos.append(new_todo)
    return new_todo

delete_todo(todo_id)

Delete a to-do item by its UUID.

Parameters:

Name Type Description Default
todo_id UUID

The unique identifier of the to-do item to delete.

required

Returns:

Type Description

No content if deletion is successful.

Raises:

Type Description
HTTPException

If the to-do item does not exist.

Source code in backend/example.py
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
@app.delete("/todos/{todo_id}", status_code=204, tags=["To-Dos"])
def delete_todo(todo_id: UUID):
    """
    Delete a to-do item by its UUID.

    Args:
        todo_id (UUID): The unique identifier of the to-do item to delete.

    Returns:
        No content if deletion is successful.

    Raises:
        HTTPException: If the to-do item does not exist.
    """
    for idx, todo in enumerate(todos):
        if todo.id == todo_id:
            todos.pop(idx)
            return
    raise HTTPException(status_code=404, detail="To-Do not found")

get_all_todos()

Retrieve all to-do items.

Returns:

Type Description

A list of all to-do tasks currently stored in memory.

Source code in backend/example.py
49
50
51
52
53
54
55
56
57
@app.get("/todos", response_model=List[ToDo], tags=["To-Dos"])
def get_all_todos():
    """
    Retrieve all to-do items.

    Returns:
        A list of all to-do tasks currently stored in memory.
    """
    return todos

get_todo(todo_id)

Retrieve a single to-do item by its UUID.

Parameters:

Name Type Description Default
todo_id UUID

The unique identifier of the to-do item.

required

Returns:

Type Description

The to-do item matching the given UUID.

Raises:

Type Description
HTTPException

If no item with the given UUID is found.

Source code in backend/example.py
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
@app.get("/todos/{todo_id}", response_model=ToDo, tags=["To-Dos"])
def get_todo(todo_id: UUID):
    """
    Retrieve a single to-do item by its UUID.

    Args:
        todo_id (UUID): The unique identifier of the to-do item.

    Returns:
        The to-do item matching the given UUID.

    Raises:
        HTTPException: If no item with the given UUID is found.
    """
    for todo in todos:
        if todo.id == todo_id:
            return todo
    raise HTTPException(status_code=404, detail="To-Do not found")

read_root()

Root endpoint for health check or welcome message.

Returns a simple JSON message indicating the API is working.

Source code in backend/example.py
40
41
42
43
44
45
46
47
@app.get("/", tags=["Root"])
def read_root():
    """
    Root endpoint for health check or welcome message.

    Returns a simple JSON message indicating the API is working.
    """
    return {"message": "Welcome to the To-Do API!"}

update_todo(todo_id, updated_todo)

Update an existing to-do item.

Parameters:

Name Type Description Default
todo_id UUID

The UUID of the to-do item to update.

required
updated_todo ToDoCreate

The updated task data.

required

Returns:

Type Description

The updated to-do item.

Raises:

Type Description
HTTPException

If the to-do item does not exist.

Source code in backend/example.py
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
@app.put("/todos/{todo_id}", response_model=ToDo, tags=["To-Dos"])
def update_todo(todo_id: UUID, updated_todo: ToDoCreate):
    """
    Update an existing to-do item.

    Args:
        todo_id (UUID): The UUID of the to-do item to update.
        updated_todo (ToDoCreate): The updated task data.

    Returns:
        The updated to-do item.

    Raises:
        HTTPException: If the to-do item does not exist.
    """
    for idx, todo in enumerate(todos):
        if todo.id == todo_id:
            todos[idx] = ToDo(id=todo_id, **updated_todo.dict())
            return todos[idx]
    raise HTTPException(status_code=404, detail="To-Do not found")