Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Atomic Operations and inclusion of related resources #1576

Open
tobyzerner opened this issue Aug 4, 2021 · 3 comments
Open

Atomic Operations and inclusion of related resources #1576

tobyzerner opened this issue Aug 4, 2021 · 3 comments
Labels
extension Related to existing and proposed extensions as well as extensions in general

Comments

@tobyzerner
Copy link
Contributor

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",
        "...": "..."
      }
    ]
  }]
}
@tobyzerner tobyzerner changed the title Atomic Operations and compound documents Atomic Operations and inclusion of related resources Aug 4, 2021
@tobyzerner
Copy link
Contributor Author

tobyzerner commented Aug 17, 2021

Another consideration is that it could also be useful to be able to specify other query parameters, like fields for sparse field sets. So perhaps these could all be wrapped in a params object:

{
  "atomic:operations": [{
    "op": "add",
    "href": "/blogPosts",
    "params": {
      "include": ["author"],
      "fields": {"users": ["name", "email"]}
    },
    "data": {
      // ...
    }
  }]
}

@freddrake
Copy link
Contributor

Another consideration is that it could also be useful to be able to specify other query parameters, like fields for sparse field sets. So perhaps these could all be wrapped in a params object:

It would be good if the specification indicated whether query parameters should be included in the href field; if not, then a side-structure like @tobyzerner's "params" suggestion would be very helpful.

@dgeb
Copy link
Member

dgeb commented Aug 29, 2021

@tobyzerner thanks for pointing out this oversight. I believe that inclusion of query params in the href member as a means to control the shape of the response document would be inappropriate. Instead I favor the introduction of a params member, which was in the original operations PR. It will need a bit further specificity, as discussed in the comments.

@jelhan jelhan added the extension Related to existing and proposed extensions as well as extensions in general label Feb 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
extension Related to existing and proposed extensions as well as extensions in general
Projects
None yet
Development

No branches or pull requests

4 participants