Results 1 to 7 of 7

Thread: Integrate Extjs with HAL REST

  1. #1
    Sencha User
    Join Date
    May 2011
    Posts
    6
    Answers
    1

    Default Answered: Integrate Extjs with HAL REST

    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 or any JS library supporting HAL, with Extjs data model, to link Stores with the server through HAL.

    Whats are the pros and cons of a such architecture ?

  2. this is the base class model, so all the models should inheret from it:

    Code:
    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'
                }
    
            }
        }
    
    });

  3. #2
    Sencha User
    Join Date
    Feb 2013
    Location
    California
    Posts
    11,985
    Answers
    506

    Default

    This post might be helpful to you:
    http://www.sencha.com/forum/showthread.php?237508#3

  4. #3
    Sencha User
    Join Date
    May 2011
    Posts
    6
    Answers
    1

    Default

    thanks for your reply, DaveJs it is not active anymore, i think i will use a customized rest proxy.

  5. #4
    Sencha Premium Member
    Join Date
    Apr 2010
    Posts
    51
    Answers
    1

    Default

    Quote Originally Posted by geogeek View Post
    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?

  6. #5
    Sencha User
    Join Date
    May 2011
    Posts
    6
    Answers
    1

    Default

    this is the base class model, so all the models should inheret from it:

    Code:
    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'
                }
    
            }
        }
    
    });

  7. #6
    Sencha User mysticav's Avatar
    Join Date
    Mar 2007
    Location
    Mexico
    Posts
    531
    Answers
    4

    Default

    What about loading a model directly:

    Code:
    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 ?

  8. #7
    Sencha User mysticav's Avatar
    Join Date
    Mar 2007
    Location
    Mexico
    Posts
    531
    Answers
    4

    Default

    Here is the solution to dynamically handle the rootProperty content for collections or single records:
    Code:
    rootProperty: function(raw) {
        return raw._embedded ? raw._embedded[Ext.util.Format.uncapitalize(this._model.entityName)] : raw;
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •