-
I've looked at the tutorials section but I couldn't answer this question: can you set the amount of entries in each page? EDIT: I had missed this page. But it's still not clear where I should pass the {
"offset": 0,
"limit": 50
} dictionary |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Ok I may be confusing the meaning of that page. I'll explain my use-case and maybe it'll be clear what I'm asking: I want to set a max size on the pages. This is for a commercial API and I don't want the users to be able to set an arbitrary size, I want to limit that or fix it to a constant size. |
Beta Was this translation helpful? Give feedback.
-
Hi @nareto, Sorry for the long response. You can create your own Page class. If you want fixed page size: from typing import TypeVar, Literal, Generic
from fastapi import Query
from fastapi_pagination import Page as BasePage, Params as BaseParams
T = TypeVar("T")
class Params(BaseParams):
size: Literal[50] = Query(50, description="Page size")
class Page(BasePage[T], Generic[T]):
__params_type__ = Params If you want custom constraints page size: from typing import TypeVar
from fastapi import Query
from fastapi_pagination import Page as BasePage, Params as BaseParams
T = TypeVar("T")
class Params(BaseParams):
size: int = Query(10, ge=1, le=10, description="Page size")
class Page(BasePage[T]):
__params_type__ = Params |
Beta Was this translation helpful? Give feedback.
Hi @nareto,
Sorry for the long response.
You can create your own Page class.
If you want fixed page size:
If you want custom constraints page size: