API Endpoints

calculator

This module expose endpoints with main app features

addition(a, b) async

Performs the addition of two float values

Returns:
  • Dict[str, float]

    Dict[str, float]: single key dict with result of the operation

Source code in src/api/calculator.py
13
14
15
16
17
18
19
20
@router.get("/addition/", tags=["Calculator"], status_code=status.HTTP_200_OK)
async def addition(a: float, b: float) -> Dict[str, float]:
    """Performs the addition of two float values

    Returns:
        Dict[str, float]: single key dict with result of the operation
    """
    return {"result": Calculator.suma(a, b)}

divide(a, b) async

Performs the division of two float values. Response model is None due to conditional float | ZeroDivisionError is not supported by pydantic.

Returns:
  • Dict[str, float | ZeroDivisionError]

    Dict[str, float]: single key dict with result of the operation

Source code in src/api/calculator.py
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
@router.get(
    "/divide/",
    tags=["Calculator"],
    response_model=None,
    status_code=status.HTTP_200_OK,
)
async def divide(a: float, b: float) -> Dict[str, float | ZeroDivisionError]:
    """Performs the division of two float values.
    Response model is None due to conditional float | ZeroDivisionError
    is not supported by pydantic.

    Returns:
        Dict[str, float]: single key dict with result of the operation
    """
    return {"result": Calculator.division(a, b)}

multiply(a, b) async

Performs the multiplication of two float values

Returns:
  • Dict[str, float]

    Dict[str, float]: single key dict with result of the operation

Source code in src/api/calculator.py
33
34
35
36
37
38
39
40
@router.get("/multiply/", tags=["Calculator"], status_code=status.HTTP_200_OK)
async def multiply(a: float, b: float) -> Dict[str, float]:
    """Performs the multiplication of two float values

    Returns:
        Dict[str, float]: single key dict with result of the operation
    """
    return {"result": Calculator.multiplicacion(a, b)}

substraction(a, b) async

Performs the substraction of two float values

Returns:
  • Dict[str, float]

    Dict[str, float]: single key dict with result of the operation

Source code in src/api/calculator.py
23
24
25
26
27
28
29
30
@router.get("/substract/", tags=["Calculator"], status_code=status.HTTP_200_OK)
async def substraction(a: float, b: float) -> Dict[str, float]:
    """Performs the substraction of two float values

    Returns:
        Dict[str, float]: single key dict with result of the operation
    """
    return {"result": Calculator.resta(a, b)}

health

API Health endpoints used to monitor the application from external tools and applications

get_health() async

Returns a dictionary with internal app status

Returns:
  • Dict[str, str]

    Dict[str, str]: single key dict with status message

Source code in src/api/health.py
12
13
14
15
16
17
18
19
@router.get("/status/", tags=["Health"], status_code=status.HTTP_200_OK)
async def get_health() -> Dict[str, str]:
    """Returns a dictionary with internal app status

    Returns:
        Dict[str, str]: single key dict with status message
    """
    return {"status": "OK"}