-
How can we modify our pagination to include an option for the user to retrieve all the data at once (for example send per_page = -1), without pagination, while still allowing them to use pagination if they choose to do so? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hi @Aissi17, Now from fastapi import FastAPI
from pydantic import BaseModel
from fastapi_pagination import Page, add_pagination, paginate
from fastapi_pagination.default import OptionalParams
Page = Page.with_params(OptionalParams)
app = FastAPI()
add_pagination(app)
class UserOut(BaseModel):
name: str
surname: str
users = [
UserOut(name="Steve", surname="Rogers"),
UserOut(name="Tony", surname="Stark"),
UserOut(name="Bruce", surname="Banner"),
]
@app.get('/users', response_model=Page[UserOut])
async def get_users():
return paginate(users)
if __name__ == '__main__':
import uvicorn
uvicorn.run(app) |
Beta Was this translation helpful? Give feedback.
-
How do you get away from the linting error that comes from this example. Possible related to this issue here in Pyright which the author claims to not be a bug but poor hinting on the implementation side. |
Beta Was this translation helpful? Give feedback.
Hi @Aissi17,
Now
fastapi-pagination
supports optional params: