1

How should a response for a set of links be in order to comply with REST principles (HATEOAS) and HAL (specification, Internet-draft)?

Is it alright to have no attributes on the first level of the JSON body and have just the _links section with the self link and the _embedded section with the links found for that particular request?

UPDATE: Example

Request to: http://localhost:5555/myservice/titles/meow/kittens

Returns:

{
  "_links": {
    "next": {
      "href": "/myservice/titles/meow/kittens?page=2"
    },
    "self": {
      "href": "/myservice/titles/meow/kittens"
    },
    "anchestor": {
      "href": "/myservice/titles/meow"
    }
  },
  "_embedded": {
    "linksINeed": [
      {
        "title": "kitten play",
        "_links": {
          "self": {
            "href": "/myservice/titles/kitten-play"
          }
        }
      },
      ...
      {
        "title": "kitten eat",
        "_links": {
          "self": {
            "href": "/myservice/titles/kitten-eat"
          }
        }
      }
    ]
  }
}

Is this valid RESTful HAL JSON ? Thanks

Community
  • 1
  • 1
Gabe
  • 5,997
  • 5
  • 46
  • 92
  • 1
    Yes, provided that your next and self links are consistent with the Link Relation Type Registry. https://tools.ietf.org/html/rfc5988#section-6.2.2 – VoiceOfUnreason Jun 30 '16 at 03:07

1 Answers1

-1

An empty JSON body as in returning a resource with 0 properties? That sounds a bit like you can do without that resource altogether. What would the self link contain if there's no property through which you can uniquely identify that resource? That wouldn't work even if you had properties but would not instantiate them.

If it's the root, you can at least have something like an ApiVersion resource with a VersionNumber property, for example.

Otherwise I guess it could be feasible in more exotic scenarios like deleting a resource and still providing links to another one (its former parent?), although that would probably merit just a HttpStatusCode 204 No Content.

Alexandru Marculescu
  • 5,569
  • 6
  • 34
  • 50