w20-framework / w20

W20 is a Web framework, built upon a powerful RequireJS/AngularJS/Bootstrap mix to help you develop single page applications.
https://w20-framework.github.io/
Mozilla Public License 2.0
8 stars 9 forks source link

Bug in Hypermedia support #80

Open Magador opened 7 years ago

Magador commented 7 years ago

According to the JSON HAL Draft, section 4.1.1:

It [the "_links" property] is an object whose property names are link relation types (as defined by RFC5988) and values are either a Link Object or an array of Link Objects.

So, according to the draft, the following HAL representation is correct:

{
  "_links": {
    "self": { "href": "/orders/523" },
    "warehouse": { "href": "/warehouse/56" },
    "people": [
      { "href": "/people/873" },
      { "href": "/people/874" }
    ]
  },
  "currency": "USD",
  "status": "shipped",
  "total": 10.20
}

But when the Hypermedia module tries to convert these links to absolute links, it throws an error since the Hypermedia module only accepts a _links property where the values are Link Objects, but not arrays of Link Objects.

See an example below:

angular.forEach(links, function (linkValue, linkKey) { // linkValue = [Object, Object], linkKey = "people"
  if (linkValue.href.charAt(0) === '/') { // TypeError: Cannot read property 'charAt' of undefined
    linkValue.href = host + linkValue.href;
    links[linkKey] = linkValue;
  }
});
maneesh-innani commented 5 years ago

Is this going to have full features like spring rest HATEOAS? So you can know all exposed restful service links for given path.