Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No need check pagination.isValid() in handleIndex #306

Open
imhuytq opened this issue Nov 11, 2017 · 2 comments
Open

No need check pagination.isValid() in handleIndex #306

imhuytq opened this issue Nov 11, 2017 · 2 comments

Comments

@imhuytq
Copy link

imhuytq commented Nov 11, 2017

In some cases, I want to use only page[number] without page[size]. Currently handleIndex will ignore PaginatedFindAll (Because pagination.isValid() is false) and call to FindAll. If this time my resource does not implement FindAll, then the 404 error.

I think we do not need to call pagination.isValid() in handleIndex, let this be for PaginatedFindAll. So I can customize my API more easily.

What do you think about this?

@sharpner
Copy link
Member

Depends on the reason of why do you want to omit the page size.

I've been trying to wrap my head around the idea but it kinda always results in some kind of fallback size which the server knows. Since jsonapi wants to give the client full control of the backend, I'd rather not omit it, if that's the case.

If the case is, that for the first page you want to specify the page length, and for further requests omit it, then we should look into supporting cursor based pagination (http://jsonapi.org/format/#fetching-pagination) which we currently don't support but is in my opinion the better solution.

@imhuytq
Copy link
Author

imhuytq commented Nov 11, 2017

For example, I have a resource called Profile. When my client requests to /profiles without any page[number] or page[size] parameters, I want the server to return to the client a paginated result and include the links (next, prev, first, last). Currently I will have to manually create the list of links in the FindAll function and insert it into the Response.

I think instead of using pagination.isValid() in handleIndex, we will validate the parameters in PaginatedFindAll, and PaginatedFindAll will return a "PaginationParams" struct like this:

type PaginationParams struct {
	number, size, offset, limit uint64
        total                                    uint
}

Finally, the "paginationQueryParams" struct will use the above data to generate links.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants