Skip to content

Reference

dsg_lib.fastapi_functions.default_endpoints

create_default_router(config)

Creates a router with default endpoints, including a configurable robots.txt.

Parameters:

Name Type Description Default
config List[Dict[str, str]]

A list of dictionaries specifying which bots are allowed or disallowed.

required

Returns:

Name Type Description
APIRouter APIRouter

A FastAPI router with the default endpoints.

Source code in dsg_lib/fastapi_functions/default_endpoints.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
def create_default_router(config: List[Dict[str, str]]) -> APIRouter:
    """
    Creates a router with default endpoints, including a configurable robots.txt.

    Args:
        config (List[Dict[str, str]]): A list of dictionaries specifying which bots are allowed or disallowed.

    Returns:
        APIRouter: A FastAPI router with the default endpoints.
    """
    router = APIRouter()

    @router.get("/robots.txt", response_class=Response)
    async def robots_txt():
        """
        Generates a robots.txt file based on the provided configuration.

        Returns:
            Response: The robots.txt content.
        """
        robots_txt_content = build_robots_txt(config)
        return Response(robots_txt_content, media_type="text/plain")

    return router