A project I have recently been working on, I used a REST-api with hateoas support.
Explained shortly, this means that the REST-api responses contain links to different REST calls you can make. This way, if any url changes, this does not affect the application, since the correct links are given in the responses of the REST calls.
To integrate this feature, I extended the default REST adapter. Now it keeps track of all the correct links and updates them when necessary.
I was wondering whether this would be a usefull feature in Ember.js. If so, I could maybe provide the people of Ember.js with my code, or fork the project or something.
Let me know what you think,
Greatings
Yes please! I’ve been super interested in how a HATEOAS API might interface with Ember Data, would love to see how you approached this.
Unfortunately, now it is not integrated with EmberData. I just return the json data as received. However I think it is still possible to integrate it with Ember Data.
Currently I have just overwritten the find function of the restadapter. First of all, I have a resolveLink function which will search for the correct link (given the entity,id and such). Afterwards I do a call to the ajax function. The response from this ajax function will be filtered for elements with key “links”. Any elements in a “links” element will be inserted in the available links (possibly updating some links). The rest of the ajax result is returned to the user.
If you have any further questions, just let me know. I can show you the code as it is right now. However, it will definitely need some work before it can be applied in different contexts.
We just struggled through integrating Ember with Apigility in PHP and dealing with making Ember follow links rather than looking for embedded records, which sounds similar to what you’re working on.
We ended up using hal9000 (https://github.com/201-created/ember-data-hal-9000), but had to modify it because links with dashes in the names were getting messed up by Ember’s transformations. It’s a good place to start, but it doesn’t quite handle 1 to 1 relationships.
This indeed very similiar to the adapter I wrote. The syntax of the json links is a little bit different, however I wrote this part quite generic. So it should be quite easy to make the json structure configurable.
This is link to my code. Please note that there are some implementation details which are quite specific for the REST-api I was working on, however if there is interest in this functionality, I could put some extra time in it so it is fully generic and configurable.
I also appologize for the lack of comments. I will add these shortly.