Do JSONAPI allows Compound Documents return partial include's resource's attribute?

For example, when request through http://example.com/articles/1 return this:

{
  "data": {
    "type": "articles",
    "id": "1",
    "attributes": {
      "title": "JSON API paints my bikeshed!"
    },
    "links": {
      "self": "http://example.com/articles/1"
    },
    "relationships": {
      "author": {
        "links": {
          "self": "http://example.com/articles/1/relationships/author",
          "related": "http://example.com/articles/1/author"
        },
        "data": { "type": "people", "id": "9" }
      }
  },
  "included": [{
    "type": "people",
    "id": "9",
    "attributes": {
      "first-name": "Dan",
      "last-name": "Gebhardt",
      "twitter": "dgeb"
    },
    "links": {
      "self": "http://example.com/people/9"
    }
  }]
}

But when request using http://example.com/people/9 get this NOTE: with facebook:

{
  "data": {
    "type": "people",
    "id": "9",
    "attributes": {
      "first-name": "Dan",
      "last-name": "Gebhardt",
      "twitter": "dgeb",
      "facebook": "123"
    },
    "links": {
      "self": "http://example.com/people/9"
    }
  }
}

Is the first response valid?

Yes, the first response is valid. As the API designer, you have all the flexibility you need to return partial representations of included resources. Best practice would probably be to return the full representation unless you have a compelling reason not to return it. However, as far as the specification is concerned I would say the first is completely valid.

1 Like