codegram/hyperclient

Loading full representations of embedded resources

Closed this issue · 5 comments

If the changes I proposed in #34 happen, it will be common for a consumer to unknowingly receive a partial representation of a resource.

HAL draft, Section 4.1.2:

Embedded Resources MAY be a full, partial, or inconsistent version of the representation served from the target URI.

For example, say a root resource has the an embedded categories relation:

{
  "_embedded": {
    "categories": [
      {"name": "Hypermedia", "_links": {"self": {"href": "http://example.com/hypermedia"}}}
    ]
  }

Following the self link on the embedded category gives something like this:

{
  "id": 1,
  "name": "Hypermedia",
  "_embedded": {
    "talks": [
      {"title": "Introduction to Hypermedia", "_links": {"self": {"href": "..."}}}
    ]
  }

If the proposed changes in #34 happen, I would imagine a consumer doing something like:

Hyperclient.new(url).categories.each do |category|
  puts category.attributes.name
  category.talks.each do |talk|
    puts "* #{talk.attributes.title}"
  end
end

The problem is that this could would blow up when the consumer calls category.talks because the category resource has no clue that it is only a partial representation.

It would be amazing if hyperclient were aware of this and could attempt to reload the partial resource (which it knows is partial because it came from an embed) from the self link if an unknown attribute or relation is requested.

This should be fairly easy to implement, and still be clean, but I wanted to get your thoughts before starting on it.

txus commented

It sounds good to me. What's your opinion @oriolgual ?

👍

Oriol Gual

On Thursday, September 19, 2013 at 11:44 AM, Josep M. Bach wrote:

It sounds good to me. What's your opinion @oriolgual (https://github.com/oriolgual) ?


Reply to this email directly or view it on GitHub (#35 (comment)).

txus commented

@bkeepers go ahead! :)

I'm actually not working on the project that uses this anymore. I hope to be working on a hypermedia API again soon, but probably won't be contributing anything until then.

txus commented

Ok, I'll close this for now. Feel free to reopen whenever :)