Search Options

Results per page
Sort
Preferred Languages
Advance

Results 221 - 230 of 274 for head_item (0.04 sec)

  1. docs_src/query_params_str_validations/tutorial015_an_py39.py

    
    def check_valid_id(id: str):
        if not id.startswith(("isbn-", "imdb-")):
            raise ValueError('Invalid ID format, it must start with "isbn-" or "imdb-"')
        return id
    
    
    @app.get("/items/")
    async def read_items(
        id: Annotated[Union[str, None], AfterValidator(check_valid_id)] = None,
    ):
        if id:
            item = data.get(id)
        else:
            id, item = random.choice(list(data.items()))
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Sat Mar 01 22:02:35 UTC 2025
    - 781 bytes
    - Viewed (0)
  2. docs_src/dependency_testing/tutorial001_an_py39.py

    app = FastAPI()
    
    
    async def common_parameters(
        q: Union[str, None] = None, skip: int = 0, limit: int = 100
    ):
        return {"q": q, "skip": skip, "limit": limit}
    
    
    @app.get("/items/")
    async def read_items(commons: Annotated[dict, Depends(common_parameters)]):
        return {"message": "Hello Items!", "params": commons}
    
    
    @app.get("/users/")
    async def read_users(commons: Annotated[dict, Depends(common_parameters)]):
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Sat Mar 18 12:29:59 UTC 2023
    - 1.5K bytes
    - Viewed (0)
  3. tests/test_security_oauth2_password_bearer_optional_description.py

    app = FastAPI()
    
    oauth2_scheme = OAuth2PasswordBearer(
        tokenUrl="/token",
        description="OAuth2PasswordBearer security scheme",
        auto_error=False,
    )
    
    
    @app.get("/items/")
    async def read_items(token: Optional[str] = Security(oauth2_scheme)):
        if token is None:
            return {"msg": "Create an account first"}
        return {"token": token}
    
    
    client = TestClient(app)
    
    
    def test_no_token():
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Fri Jun 30 18:25:16 UTC 2023
    - 2.2K bytes
    - Viewed (0)
  4. fastapi/security/api_key.py

        from fastapi import Depends, FastAPI
        from fastapi.security import APIKeyQuery
    
        app = FastAPI()
    
        query_scheme = APIKeyQuery(name="api_key")
    
    
        @app.get("/items/")
        async def read_items(api_key: str = Depends(query_scheme)):
            return {"api_key": api_key}
        ```
        """
    
        def __init__(
            self,
            *,
            name: Annotated[
                str,
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Wed Dec 17 21:25:59 UTC 2025
    - 9.6K bytes
    - Viewed (1)
  5. docs_src/dependency_testing/tutorial001_py39.py

    app = FastAPI()
    
    
    async def common_parameters(
        q: Union[str, None] = None, skip: int = 0, limit: int = 100
    ):
        return {"q": q, "skip": skip, "limit": limit}
    
    
    @app.get("/items/")
    async def read_items(commons: dict = Depends(common_parameters)):
        return {"message": "Hello Items!", "params": commons}
    
    
    @app.get("/users/")
    async def read_users(commons: dict = Depends(common_parameters)):
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Wed Dec 17 20:41:43 UTC 2025
    - 1.5K bytes
    - Viewed (0)
  6. docs_src/dependency_testing/tutorial001_an_py310.py

    app = FastAPI()
    
    
    async def common_parameters(q: str | None = None, skip: int = 0, limit: int = 100):
        return {"q": q, "skip": skip, "limit": limit}
    
    
    @app.get("/items/")
    async def read_items(commons: Annotated[dict, Depends(common_parameters)]):
        return {"message": "Hello Items!", "params": commons}
    
    
    @app.get("/users/")
    async def read_users(commons: Annotated[dict, Depends(common_parameters)]):
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Sat Mar 18 12:29:59 UTC 2023
    - 1.5K bytes
    - Viewed (0)
  7. tests/test_security_oauth2_authorization_code_bearer_description.py

    oauth2_scheme = OAuth2AuthorizationCodeBearer(
        authorizationUrl="authorize",
        tokenUrl="token",
        description="OAuth2 Code Bearer",
        auto_error=True,
    )
    
    
    @app.get("/items/")
    async def read_items(token: Optional[str] = Security(oauth2_scheme)):
        return {"token": token}
    
    
    client = TestClient(app)
    
    
    def test_no_token():
        response = client.get("/items")
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Fri Jun 30 18:25:16 UTC 2023
    - 2.4K bytes
    - Viewed (0)
  8. tests/test_security_oauth2_password_bearer_optional.py

    from fastapi.security import OAuth2PasswordBearer
    from fastapi.testclient import TestClient
    
    app = FastAPI()
    
    oauth2_scheme = OAuth2PasswordBearer(tokenUrl="/token", auto_error=False)
    
    
    @app.get("/items/")
    async def read_items(token: Optional[str] = Security(oauth2_scheme)):
        if token is None:
            return {"msg": "Create an account first"}
        return {"token": token}
    
    
    client = TestClient(app)
    
    
    def test_no_token():
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Fri Jun 30 18:25:16 UTC 2023
    - 2.1K bytes
    - Viewed (0)
  9. docs/zh/docs/index.md

    ```Python
    from typing import Union
    
    from fastapi import FastAPI
    
    app = FastAPI()
    
    
    @app.get("/")
    def read_root():
        return {"Hello": "World"}
    
    
    @app.get("/items/{item_id}")
    def read_item(item_id: int, q: Union[str, None] = None):
        return {"item_id": item_id, "q": q}
    ```
    
    <details markdown="1">
    <summary>或者使用 <code>async def</code>...</summary>
    
    如果你的代码里会出现 `async` / `await`,请使用 `async def`:
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Sat Oct 11 17:48:49 UTC 2025
    - 18.2K bytes
    - Viewed (0)
  10. tests/test_multi_query_errors.py

    from fastapi import FastAPI, Query
    from fastapi.testclient import TestClient
    
    app = FastAPI()
    
    
    @app.get("/items/")
    def read_items(q: list[int] = Query(default=None)):
        return {"q": q}
    
    
    client = TestClient(app)
    
    
    def test_multi_query():
        response = client.get("/items/?q=5&q=6")
        assert response.status_code == 200, response.text
        assert response.json() == {"q": [5, 6]}
    
    
    def test_multi_query_incorrect():
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Sat Dec 27 18:19:10 UTC 2025
    - 3.9K bytes
    - Viewed (0)
Back to top