Skip to content

Reference

This part of the project documentation focuses on an information-oriented approach. Use it as a reference for the technical implementation of the project code.

example_app.app

get_pokemon(number=Path(title='The Pokémon to get (based on number)', ge=1, le=151))

Endpoint that returns information about Pokémon.

Parameters:

Name Type Description Default
number int

The number of the Pokémon to get

Path(title='The Pokémon to get (based on number)', ge=1, le=151)

Returns:

Type Description
dict

Awesome information about the Pokémon!

Source code in example_app/app.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
@app.get(path="/{number}", status_code=status.HTTP_200_OK)
def get_pokemon(
    number: int = Path(title="The Pokémon to get (based on number)", ge=1, le=151)
) -> dict:
    """
    Endpoint that returns information about Pokémon.
    Args:
        number: The number of the Pokémon to get
    Returns:
        Awesome information about the Pokémon!
    """
    pokemon_url: str = f"https://pokeapi.co/api/v2/pokemon/{number}"

    try:
        response: Response = httpx.get(url=pokemon_url)
    except Exception:
        raise HTTPException(
            status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
            detail=f"Could not send a request to {pokemon_url}",
        )

    if response.status_code == status.HTTP_200_OK:
        return response.json()
    else:
        raise HTTPException(status_code=response.status_code, detail=response.text)

example_app.service

Provides several sample functions.

The module contains the following functions:

  • foo(a, b) - Returns the sum of two numbers (int).
  • `bar(a)' - Returns a hello message with the input string.

bar(name='Frank Herbert')

Says 'Hello' with input.

Parameters:

Name Type Description Default
name str

input string

'Frank Herbert'

Returns:

Type Description
str

A 'Hello' message.

Source code in example_app/service.py
32
33
34
35
36
37
38
39
40
41
42
def bar(name: str = "Frank Herbert") -> str:
    """
    Says 'Hello' with input.

    Args:
        name: input string

    Returns:
        A 'Hello' message.
    """
    return f"Hello, {name}!"

foo(a, b)

This is a description what the function does.

Examples:

>>> foo(a=1, b=2)
3
>>> foo(a=4, b=15)
19

Parameters:

Name Type Description Default
a int

This is the first summand

required
b int

This is the second summand

required

Returns:

Type Description
int

The summation of a and b.

Source code in example_app/service.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
def foo(a: int, b: int) -> int:
    """
    This is a description what the function does.

    Examples:
        >>> foo(a=1, b=2)
        3
        >>> foo(a=4, b=15)
        19

    Args:
        a: This is the first summand
        b: This is the second summand

    Returns:
        The summation of a and b.
    """
    return a + b