Get all data
#542
-
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.
Answered by
uriyyo
Apr 9, 2023
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.
0 replies
Answer selected by
uriyyo
-
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.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @Aissi17,
Now
fastapi-pagination
supports optional params: