On the critical path for us to be able to adopt JSON:API in full is being able to retrieve arbitrary revisions of a piece of content. This is important for us in order to provide staging previews of our content while still allowing the main API to return the latest version of a piece of content. I would expect something like the following should work:

  • Without specifying a revision, JSON:API returns whatever the latest revision of a piece of content in a given translation that is marked as "published" (as in Core's content moderation settings, almost identical to the current way the API works). High priority
  • If a revision is specified, the specific revision is returned regardless of published state. High priority
  • Including a list of revisions with their moderation state a la Core's content moderation, revision timestamp, and whether or not the revision is published. Low priority, but nice to have in order to provide more dynamic functionality around staging revisions

Something along the lines of /jsonapi/node/article/{uuid}?version={vid} or /jsonapi/node/article/{uuid}/{vid} for retrieving a specific entity at a given revision should suffice for this. Under relationships there is currently a possible revision_uid link (which errors if you try and click on it), and something similar for revisions where the data is something like an array of objects, and links including a link for each each version would be a good way to move forward. We could even do away with the additional information if we could include off of those links

Comments

Snugug created an issue. See original summary.

e0ipso’s picture

I think that this is a good candidate for a sub-module or a separate contrib. There are many ways to do revisions (think of workspaces, or time based revisions, etc.). There are also competing formats to express those.

I don't think the JSON API module needs to be opinionated about these. However I would think that a module could use many of the JSON API tools to achieve this goal.

gabesullice’s picture

Title: Retrieve Content Revisions » Support content revisioning
Issue tags: +API-First Initiative

I think that this is a good candidate for a sub-module or a separate contrib. ... However I would think that a module could use many of the JSON API tools to achieve this goal.

I'm curious how this might work in another module, @e0ipso, it sounds like you already have some thoughts about that?

There are many ways to do revisions (think of workspaces, or time based revisions, etc.). There are also competing formats to express those.

Perhaps there is some infrastructure we could provide to establish a baseline of functionality?

For example, no matter the way revisions are done, revisions always have a "previous" version, pretty much by definition. The same is almost always true for a "canonical" or "default" version.

No matter what, there ought to be a way to express a URL for those revisions.

I like @Snugug's suggestion of: http://example.com/jsonapi/node/article/{uuid}?version={vid}, but I would slightly amend version={vid} to version={we_dont_care}, so that we aren't tied to a version identifier and so it would permit a revision provider to have aliases like version=latest

It seems to me that any complementary module would need a way to:

  1. Influence the loaded entity on an individual basis. I.e. cause JSON API to load a different revision than the default.
  2. Express the revision state. I.e. to answer the question "is this the canonical version?" "is this an editable revision?"
  3. Express how a particular revision relates to another revision.

Concretely, I think we need to decide on a URI template for addressing a particular revision and use that template to load particular revisions. I think we also need to figure out HATEOAS links such that a module can provide links to a prior, canonical, editable version etc.

Relying on RFC5829 seems like the best approach, particularly the idea that navigation between versions should be based on link relations, not JSON API relationships.

Unknowns
Collections/filtering and includes seem to be the biggest unknowns here. I'd like to propose that we simply punt on them and do only what we can without solving every possible problem.

Collections are difficult because there's no way in the entity query system to query particular revisions. One is limited to the blunt: currentRevision(), latestRevision() or allRevisions() methods.

Includes are difficult because if you attempt to include an entity while viewing a particular revision, which version of the included resource should we include?

In both cases though, I think we can #donothing to start. We don't need to support include query params in conjunction with revisions and we don't need to support the version query param on collection routes. This could be added over time as patterns emerge from initial individual GET support and as Drupal core support gets better.

wim leers’s picture

This issue is a duplicate of #2795279: [PP-2] [META] Revisions support. Also semi-related: #2832164: JSON API: forward compatibility with Workspace module.

#2946972: EntityResource: revisions support is the sister issue for core's rest.module.


This would be an extension to the JSON API spec. And JSON API 1.0 does not have an extension mechanism yet, that's being discussed in https://github.com/json-api/json-api/issues/1207, and we (Drupal community/JSON API Drupal module maintainers) are participating in it. That upstream issue is blocking #2955020: Spec Compliance: JSON API's profile/extention (Fancy Filters, Drupal sorting, Drupal pagination, relationship arity) needs to be explicitly communicated.

Relevant JSON API issues for this issue: https://github.com/json-api/json-api/issues/749 + https://github.com/json-api/json-api/issues/41.


As much as I applaud opening an issue for this, I do think it'd be better to close this and move all of its comments into #2795279: [PP-2] [META] Revisions support. It's impossible to keep track of all discussions about the exact same subject/scope otherwise.

Everyone +1 to that?

gabesullice’s picture

Everyone +1 to that?

+1

I'll respond to your other points over there.

Snugug’s picture

I'm OK closing this for https://www.drupal.org/project/jsonapi/issues/2795279; I didn't find that on first-pass having not dealt with the Drupal issue queue in a while.

e0ipso’s picture

Status: Active » Closed (duplicate)

Thanks for the report @Snugug. I'll link this issue in #2795279: [PP-2] [META] Revisions support.