How to use the fastapi.Path function in fastapi

To help you get started, we’ve selected a few fastapi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tiangolo / fastapi / tests / main.py View on Github external
def get_path_param_le_ge(item_id: float = Path(..., le=3, ge=1)):
    return item_id
github tiangolo / fastapi / tests / main.py View on Github external
def get_path_param_ge(item_id: float = Path(..., ge=3)):
    return item_id
github tiangolo / fastapi / tests / main.py View on Github external
def get_path_param_gt_int(item_id: int = Path(..., gt=3)):
    return item_id
github tiangolo / fastapi / tests / main.py View on Github external
def get_path_param_lt_gt_int(item_id: int = Path(..., lt=3, gt=1)):
    return item_id
github nsidnev / fastapi-realworld-example-app / app / api / dependencies / comments.py View on Github external
async def get_comment_by_id_from_path(
    comment_id: int = Path(..., ge=1),
    article: Article = Depends(articles.get_article_by_slug_from_path),
    user: Optional[User] = Depends(
        authentication.get_current_user_authorizer(required=False)
    ),
    comments_repo: CommentsRepository = Depends(
        database.get_repository(CommentsRepository)
    ),
) -> Comment:
    try:
        return await comments_repo.get_comment_by_id(
            comment_id=comment_id, article=article, user=user
        )
    except EntityDoesNotExist:
        raise HTTPException(
            status_code=status.HTTP_404_NOT_FOUND, detail=strings.COMMENT_DOES_NOT_EXIST
        )
github tiangolo / fastapi / docs / tutorial / src / all / tutorial010.py View on Github external
async def read_items(
    item_id: int = Path(..., title="The ID of the item to get"),
    q: str = Query(None, alias="item-query"),
):
    results = {"item_id": item_id}
    if q:
        results.update({"q": q})
    return results
github tiangolo / fastapi / docs / src / path_params_numeric_validations / tutorial002.py View on Github external
async def read_items(
    q: str, item_id: int = Path(..., title="The ID of the item to get")
):
    results = {"item_id": item_id}
    if q:
        results.update({"q": q})
    return results
github tiangolo / fastapi / docs / src / path_params_numeric_validations / tutorial004.py View on Github external
async def read_items(
    *, item_id: int = Path(..., title="The ID of the item to get", ge=1), q: str
):
    results = {"item_id": item_id}
    if q:
        results.update({"q": q})
    return results
github nsidnev / fastapi-realworld-example-app / app / api / api_v1 / endpoints / comment.py View on Github external
async def delete_comment_from_article(
    slug: str = Path(..., min_length=1),
    id: int = Path(..., ge=1),
    user: User = Depends(get_current_user_authorizer()),
    db: DataBase = Depends(get_database),
):
    async with db.pool.acquire() as conn:
        await get_article_or_404(conn, slug, user.username)

        await delete_comment(conn, id, user.username)
github tiangolo / fastapi / docs / src / path_params_numeric_validations / tutorial006.py View on Github external
async def read_items(
    *,
    item_id: int = Path(..., title="The ID of the item to get", ge=0, le=1000),
    q: str,
    size: float = Query(..., gt=0, lt=10.5)
):
    results = {"item_id": item_id}
    if q:
        results.update({"q": q})
    return results