jcassee / angular-hypermedia

Hypermedia REST API client for AngularJS applications
MIT License
38 stars 5 forks source link

Match on encoded url in browser and non-encoded self link fails #35

Closed WidoBurg closed 8 years ago

WidoBurg commented 8 years ago

We are facing the issue that the browser encodes the url but the self link is not. Therefore the HAL-api throwing an error when matching the two. So a valid error.

$update: {value: function (data, links) {
        links = links || {};
        var selfHref = ((data._links || {}).self || {}).href;
        if (!selfHref) selfHref = (links.self || {}).href;
        if (selfHref != this.$uri) {
          throw new Error("Self link href differs: expected '" + this.$uri + "', was " + angular.toJson(selfHref));
        }

Let the server encode the self link is a possible solution. But the HAL API can also do the encoding before matching. What do you think?

jcassee commented 8 years ago

Well, this is an interesting problem! The invariant selfHref == this.$uri is necessary because the URI is both the key in the context used to look up resources and the URL used in HTTP requests.

I am not sure yet how we should fix this. Can you give a concrete example?

WidoBurg commented 8 years ago

Sure.

angular.js:12520 Error: Self link href differs: expected 'http://localhost:9000/holmes/rest/inspecties/10645/registerobjecten/zoek?zoekterm=ID%3ASP-12059', was "http://localhost:9000/holmes/rest/inspecties/10645/registerobjecten/zoek?zoekterm=ID:SP-12059" at IlentResource.value (hypermedia.js:407)

WidoBurg commented 8 years ago

Issue is resolved with 0.10.0.