Skip to content

Get all data #542

Answered by uriyyo
Aissi17 asked this question in Q&A
Feb 15, 2023 · 2 comments
Discussion options

You must be logged in to vote

Hi @Aissi17,

Now fastapi-pagination supports optional params:

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)

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by uriyyo
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants