codegram / hyperclient

HyperClient is a Ruby Hypermedia API client.
MIT License
153 stars 35 forks source link

Dealing With Other Media Types #42

Open benhamill opened 11 years ago

benhamill commented 11 years ago

Imagine I get some HAL from a server that looks like this (in part, maybe):

{
  '_links': {
    'self': { 'href': '/users/12345' },
    'profile_image': { 'href': '/user/12345/face' }
  }
}

And I am super interested in profile images, so I want to get that sucker. Right now, if I call, you know, user.links.profile_image.resource I get back a sort of confused Hyperclient::Resource that can't tell me the media type is jpeg or whatever. I could call get instead of resource, but then I have to know more about the foreign API.

I wonder if we shouldn't make it so that Hyperclient, when it sees a response from a server that isn't Content-Type: application/hal+json (or maybe a list to include normal application/json and that a user could add to), it just hands over the Faraday::Response object or something similar. Basically, it punts and says, "This isn't hypermedia I know about, you handle this bullshit."

Thoughts?

benhamill commented 11 years ago

Oh. One more thing: This sort of ties into #41 in that, if Link#resource isn't a thing, and everyone always used the methods named after HTTP verbs, then those methods would be the point where we'd do the intelligent thing.

dblock commented 10 years ago

+1, I think that it would be very helpful to differentiate the media types when following hyperlinks. Definitely return some base type that's not JSON to start.

dblock commented 10 years ago

In https://github.com/codegram/hyperclient/pull/73 I made a change that returned Resource objects from all these methods. We could just examine the content type of the response before assigning these and return something else.