Problem/Motivation

In order to be compliant with the JSON API specification, we need to provide the links key to describe the different resources being returned in the GET responses.

Proposed resolution

Add the links based on the current request in the different normalizers.

Comments

e0ipso created an issue. See original summary.

e0ipso’s picture

Status: Active » Needs review
StatusFileSize
new30.59 KB

Initial patch to add the:

  • Document link
  • Relationship link
  • Related link

Output with the patch applied (you can see tests as well):

{
  "data": {
    "type": "article",
    "id": "3",
    "attributes": {
      "nid": "3",
      "uuid": "c23ff989-8440-4ac2-a38c-0e232e0b120f",
      "vid": "3",
      "langcode": "en",
      "type": "article",
      "title": "Second article for testing",
      "status": "1",
      "created": "1463233887",
      "changed": "1463233940",
      "promote": "1",
      "sticky": "0",
      "revision_timestamp": "1463233922",
      "revision_log": null,
      "revision_translation_affected": "1",
      "default_langcode": "1",
      "path": null,
      "body": {
        "value": "<p>dummy dummy lorem<\/p>\r\n",
        "format": "basic_html",
        "summary": ""
      },
      "comment": {
        "status": "2",
        "cid": "0",
        "last_comment_timestamp": "1463233922",
        "last_comment_name": null,
        "last_comment_uid": "1",
        "comment_count": "0"
      }
    },
    "relationships": {
      "uid": {
        "data": {
          "type": "user",
          "id": "1"
        },
        "links": {
          "self": "http:\/\/d8dev.local\/api\/article\/3\/relationships\/uid?_format=api_json",
          "related": "http:\/\/d8dev.local\/api\/article\/3\/uid?_format=api_json"
        }
      },
      "revision_uid": {
        "data": {
          "type": "user",
          "id": "1"
        },
        "links": {
          "self": "http:\/\/d8dev.local\/api\/article\/3\/relationships\/revision_uid?_format=api_json",
          "related": "http:\/\/d8dev.local\/api\/article\/3\/revision_uid?_format=api_json"
        }
      },
      "field_category": {
        "data": {
          "type": "category",
          "id": "2"
        },
        "links": {
          "self": "http:\/\/d8dev.local\/api\/article\/3\/relationships\/field_category?_format=api_json",
          "related": "http:\/\/d8dev.local\/api\/article\/3\/field_category?_format=api_json"
        }
      },
      "field_image": {
        "data": null
      },
      "field_tags": {
        "data": [
          {
            "type": "tags",
            "id": "7"
          },
          {
            "type": "tags",
            "id": "5"
          }
        ],
        "links": {
          "self": "http:\/\/d8dev.local\/api\/article\/3\/relationships\/field_tags?_format=api_json",
          "related": "http:\/\/d8dev.local\/api\/article\/3\/field_tags?_format=api_json"
        }
      }
    },
    "links": {
      "self": "http:\/\/d8dev.local\/api\/article\/3?_format=api_json"
    }
  },
  "links": {
    "self": "http:\/\/d8dev.local\/api\/article\/3?_format=api_json&XDEBUG_SESSION_START=PHPSTORM"
  },
  "included": []
}

  • gabesullice committed de412eb on 8.x-1.x authored by e0ipso
    Issue #2731331 by e0ipso: [FEATURE] Add links for HATEOAS support
    
gabesullice’s picture

StatusFileSize
new30.43 KB

LGTM. Merging, had to make a small change. Patch attached.

gabesullice’s picture

Status: Needs review » Fixed

Status: Fixed » Needs work

The last submitted patch, 4: 2731331--add-links--3.patch, failed testing.

The last submitted patch, 4: 2731331--add-links--3.patch, failed testing.

gabesullice’s picture

StatusFileSize
new614 bytes

Fixing bad namespace.

  • gabesullice committed 6c9c9a0 on 8.x-1.x
    Issue #2731331 by e0ipso, gabesullice: [FEATURE] Add links for HATEOAS...
gabesullice’s picture

Status: Needs work » Active
gabesullice’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

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