restrestful-urlhateoashal-json

HAL Specification - Should self link contain query parameter?


Following the HAL specification should the self link contain the query parameter or is it ok to link to the first page? Thanks

Follows an example:

Request:

my-service/movies/123/subtitles?page=3

Actual JSON response:

{
  "count": 20,
  "pagingSize": 5,
  "_links": {
    "next": {
      "href": "/my-service/movies/123/subtitles?page=4"
    },
    "previous": {
      "href": "/my-service/movies/123/subtitles?page=2"
    },
    "self": {
      "href": "/my-service/movies/123/subtitles"
    },
    "movie": {
      "href": "/my-service/movies/123"
    }
  },
  "_embedded": {
    "subtitles": [
      {
        "id": "111",
        "_links": {
          "self": {
            "href": "/my-service/subtitles/111"
          }
        }
      },
      ...    
      {
        "id": "222",
        "_links": {
          "self": {
            "href": "/my-service/subtitles/222"
          }
        }
      }
    ]
  }
}

Solution

  • The Hypertext Application Language (HAL) proposed draft specification enforces the "href" in conformity with the "Target IRI" defined in Web Linking specification (RFC 5988).

    Applications that don't wish to register a relation type can use an extension relation type, which is a URI [RFC3986] that uniquely identifies the relation type.

    So I'd say that the self value must be unique, and thus include any (unspecified optional) query parameters.