render - formats should include model
- Dominant language
- Groovy
- Stars
- 2.9k
- Forks
- 975
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 92
Description
### Feature description
Currently Grails controllers render json with no model. This is extremely limiting and contrary to how other views work. For instance, def index() provides `"${entityName.uncapitalize()Count}"` to index.gsp, but index.json just returns a json list with no count.
Meta data is crucial for being able to properly paginate through large amount of results or even providing context.
Proper pagination should use cursors instead of offsets and using the default rendering strategy provides no mechanism for providing this meta data.
The default should be changed to a structure that provides data and meta data.
A possibility is:
```json
{
"data": [ /* the list */ ],
"meta": { /* the model */ },
}
```
For example:
```json
{
"data": [ { "name": "Bob", "id": 1 }, ... ],
"meta": { "count": 100, "cursor": "aSdFa123" }
}
```
https://jsonapi.org/format/#fetching-pagination
Contributor guide
Research direction
Start by tracing how Grails controllers render JSON for index actions and how index.json differs from index.gsp. Review the JSON:API pagination guidance linked in the issue, then define the data and metadata structure and verify that counts and cursor information are exposed without breaking existing rendering behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- groovy
- Domain
- backend-api-design
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100