Skip to content

Conversation

lonnieezell
Copy link
Member

@lonnieezell lonnieezell commented Oct 13, 2025

Description

The first in a handful of PRs to bring our API features to a more usable, modern place.

This adds a new method to the API\ResponseTrait: paginate(). This takes the model or query builder and returns a structured array with meta information and a series of links easily usable by javascript frontends.

This also follows best practices and RFC 8288 by setting the Links header with the same links in our response, and the X-Total-Count header with the total number of results. This provides information for both the human-readable portion used in frontend work, and with some machine readable information in the headers that is much easier and less error prone to be parsed.

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value (without duplication)
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@michalsn michalsn added enhancement PRs that improve existing functionalities 4.7 labels Oct 14, 2025
Copy link
Member

@michalsn michalsn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems there is a small problem with the user guide, but other than that, it looks great!

Copy link
Contributor

@neznaika0 neznaika0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

paginate() has a bug #8904.
Can we decide on the main api? Each request is now a separate standard.
Because each request can have links, descriptions, meta, and errors... Plus, it's useful when a recursive object ($user->post->tags[0]->name) contains meta.

Have you considered the json:api? https://jsonapi.org/format/

@lonnieezell
Copy link
Member Author

lonnieezell commented Oct 14, 2025

paginate() has a bug #8904. Can we decide on the main api? Each request is now a separate standard. Because each request can have links, descriptions, meta, and errors... Plus, it's useful when a recursive object ($user->post->tags[0]->name) contains meta.

Have you considered the json:api? https://jsonapi.org/format/

I'm not sure I follow 100%.

  • That paginate bug is not related to this.
  • They cannot have the exact same interface to the different paginate commands. One operates directly on the model, the other doesn't. I went back and looked at the other pagination docs and they really don't have a lot of overlap in how they operate, so I don't think it's possible to standardize between the two.
  • If a recursive object also has a meta property, that shouldn't affect the operations of this.

I am familiar with jsonapi and it is a more complex solution than I believe is appropriate for CodeIgniter to support out of the box.

@neznaika0
Copy link
Contributor

json:api is heavy at this stage. I wanted to find out the full API specification for the framework.

@lonnieezell lonnieezell merged commit 5add16d into codeigniter4:4.7 Oct 16, 2025
50 checks passed
@lonnieezell lonnieezell deleted the api-pagination branch October 16, 2025 06:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.7 enhancement PRs that improve existing functionalities

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants