Skip to content

Atomic Operations and inclusion of related resources #1576

@tobyzerner

Description

@tobyzerner

I'm currently working on an implementation of the Atomic Operations extension on both the server and client-side.

I'm wondering if there is a way for an operation to request the inclusion of related resources in its response? For example, if one of my operations is to create a resource, can I request the inclusion of resources related to the resource that has just been created?

The spec doesn't appear to say anything about it. I haven't thought about this in a huge amount of detail, but as a starting point, perhaps something like this could be allowed:

POST /operations HTTP/1.1
Host: example.org
Content-Type: application/vnd.api+json;ext="https://jsonapi.org/ext/atomic"
Accept: application/vnd.api+json;ext="https://jsonapi.org/ext/atomic"

{
  "atomic:operations": [{
    "op": "add",
    "href": "/blogPosts?include=author",
    "data": {
      "type": "articles",
      "attributes": {
        "title": "JSON API paints my bikeshed!"
      },
      "relationships": {
        "author": {
          "data": { "type": "users", "id": "1" }
        }
      }
    }
  }]
}

Or perhaps it would be better to introduce a new member which could be used in combination with both ref and href:

{
  "atomic:operations": [{
    "op": "add",
-    "href": "/blogPosts?include=author",
+    "href": "/blogPosts",
+    "include": ["author"],
    "data": {
      ...
    }
  }]
}

The response could look like this:

HTTP/1.1 200 OK
Content-Type: application/vnd.api+json;ext="https://jsonapi.org/ext/atomic"

{
  "atomic:results": [{
    "data": {
      "links": {
        "self": "http://example.com/blogPosts/13"
      },
      "type": "articles",
      "id": "13",
      "attributes": {
        "title": "JSON API paints my bikeshed!"
      },
      "relationships": {
        "author": {
          "data": { "type": "users", "id": "1" }
        }
      }
    },
    "included": [
      {
        "type": "users",
        "id": "1",
        "...": "..."
      }
    ]
  }]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    extensionRelated to existing and proposed extensions as well as extensions in general

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy