Skip to content

Error in Example 6-1: Non-existent Params class #15

@ModarYaghi

Description

@ModarYaghi

While working through "FastAPI: Modern Python Web Development," I discovered an error in Example 6-1 on page [page number]. The example imports and uses a Params class that doesn't exist in the FastAPI framework:

`
from fastapi import FastAPI, Depends, Params # Error: Params doesn't exist
app = FastAPI()

-# the dependency function:
def user_dep(name: str = Params, password: str = Params): # Error: Invalid usage
return {"name": name, "valid": True}

-# the path function / web endpoint:
@app.get("/user")
def get_user(user: dict = Depends(user_dep)) -> dict:
return user
`

FastAPI doesn't have a Params class. For required parameters in a dependency function, we should either:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions