Problem/Motivation

Currently the jsonapi client can't easily access jsonapi_views endpoints. To resolve this, either:

* JSON:API Views needs to support hypermedia (see https://www.drupal.org/project/jsonapi_views/issues/3173663)
* Or the jsonapi client could add a getView method which would allow a views endpoint to be derived without doing an index lookup.

Both would have value, but I think the client should also allow you to source views without requiring a lookup in the jsonapi index.

Steps to reproduce

* Enable jsonapi_views
* None of our existing methods will allow you to source the exposed view endpoint.

Proposed resolution

A getView method with a signature similar to getCollection

`getCollection(type, options?)`

Type in this case is a view machine name and a display_id. For example:

`getView('articles--page_1')`

This will result in a fetch request being made to `jsonapi/views/articles/page_1`

Remaining tasks

* Implement changes
* Add test coverage
* Update documentation

API changes

* Adds new getView method

Issue fork api_client-3462889

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

brianperry created an issue. See original summary.

brianperry’s picture

Issue summary: View changes

brianperry’s picture

Status: Active » Needs work

Created a draft MR with the implementation here. It doesn't include tests, as @d34dman was interested in contributing tests. This should provide a good testing overview as it requires tests for the new getView method, but also requires smaller test updates for full coverage for createUrl and createCacheKey.

d34dman’s picture

Assigned: Unassigned » d34dman
d34dman’s picture

Status: Needs work » Needs review

I have added some unit tests. They are just mostly making user that the urls are generated successfully. Please check :)

d34dman’s picture

Assigned: d34dman » Unassigned
d34dman’s picture

Status: Needs review » Reviewed & tested by the community

Thanks for the update Brian, LGTM :)

brianperry’s picture

Parent issue: » #3440572: [Meta] 1.x Roadmap

  • brianperry committed 1714bd9c on canary
    Issue #3462889 by brianperry, d34dman: JSON:API Views Support
    

  • brianperry committed 1714bd9c on main
    Issue #3462889 by brianperry, d34dman: JSON:API Views Support
    

  • brianperry committed 1714bd9c on changeset-release/main
    Issue #3462889 by brianperry, d34dman: JSON:API Views Support
    
brianperry’s picture

Status: Reviewed & tested by the community » Fixed

Merged and released as 1.2.0

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.