PDA

View Full Version : Integrate Extjs with HAL REST



geogeek
10 Feb 2015, 1:25 AM
How i could bind Spring DATA REST which outputs HAL, with ExtJS (v4.1) client, ExtJS do not have support for HAL, but how i could integrate libraries like Hyperagent.js (http://weluse.github.io/hyperagent/) or any JS library supporting HAL (https://github.com/mikekelly/hal_specification/wiki/Libraries#javascript), with Extjs data model, to link Stores with the server through HAL.

Whats are the pros and cons of a such architecture ?

Gary Schlosberg
11 Feb 2015, 2:52 PM
This post might be helpful to you:
http://www.sencha.com/forum/showthread.php?237508#3

geogeek
13 Feb 2015, 3:42 AM
thanks for your reply, DaveJs it is not active anymore, i think i will use a customized rest proxy.

jmcolyer
17 Apr 2015, 11:58 AM
thanks for your reply, DaveJs it is not active anymore, i think i will use a customized rest proxy.

Do you have code you can share for this?

geogeek
17 Apr 2015, 2:46 PM
this is the base class model, so all the models should inheret from it:


Ext.define("project.model.base", {
extend : "Ext.data.Model",
schema : {
namespace : 'project.model',
proxy : {
type : 'rest',
pageParam : false, //to remove param "page"
startParam : false, //to remove param "start"
limitParam : false, //to remove param "limit"
noCache : false, //to remove param "_dc"
appendId : false,
url : 'http://localhost:8080/{entityName}',
headers : {
'Accept' : 'application/json'

},

reader : {
type : 'json',
rootProperty : '_embedded.{entityName}'
},
writer : {
type : 'json',
writeAllFields : true,
nameProperty : 'mapping'
}

}
}

});

mysticav
12 Jun 2015, 10:10 AM
What about loading a model directly:


App.model.User.load('xxxxxxxxxxxxxxxxx', {
callback: function(model) {

}
});

In this case, according to HAL standards, I won't get a collection (_embedded), and so the rootProperty of my proxy reader won't be able to parse single calls, since the rootProperty is defined as:
rootProperty: '_embedded.{entityName:uncapitalize}'

Is there a way to define a different rootProperty when doing single GET calls ?

mysticav
12 Jun 2015, 10:30 AM
Here is the solution to dynamically handle the rootProperty content for collections or single records:

rootProperty: function(raw) {
return raw._embedded ? raw._embedded[Ext.util.Format.uncapitalize(this._model.entityName)] : raw;
}