1. #1
    Ext JS Premium Member rstuart's Avatar
    Join Date
    Jan 2008
    Location
    Brisbane, Australia
    Posts
    140
    Vote Rating
    4
    rstuart is on a distinguished road

      0  

    Default [EXTJSIV-3425] Proper support of RESTful applications

    [EXTJSIV-3425] Proper support of RESTful applications


    Just a thread to ask if we will ever see proper support for RESTful applications in Ext JS. I have been with Ext JS since version 2 and there has never been proper support for RESTful applications. I thought this was about to change with the new data package in Ext 4 but it just falls short.

    It appears the approach is to support REST with each individual model instance but not the model tree as a whole. By this I mean that Ext knows what URLs to use given a User model to create a new user or delete a user if the proxy is restful and that is great. But in true RESTful applications you only need your start URL and the anatomy of your model and you are ready to go. Let me give you an example.

    Lets assume we have this model arrangement:

    Code:
        Ext.regModel('Codebook', {
            fields: [
                {name: 'id', type: 'int'},
                {name: 'name', type: 'string'},
                {name: 'description', type: 'string'}
            ],
            associations: [
                {type: 'hasMany', model: 'Facet', name: 'facets'}
            ]
        });
        Ext.regModel('Facet', {
            fields: [
                {name: 'id', type: 'int'},
                {name: 'name', type: 'string'},
                {name: 'description', type: 'string'}
            ],
            associations: [
                {type: 'belongsTo', model: 'Codebook'},
                {type: 'hasMany', model: 'Focus', name: 'foci'}
            ]
        });
        Ext.regModel('Focus', {
            fields: [
                {name: 'id', type: 'int'},
                {name: 'code', type: 'string'},
                {name: 'description', type: 'string'}
            ],
            associations: [
                {type: 'belongsTo', model: 'Facet'}
            ]
        });
    All we need is the starting URL to get going. That start URL returns the following JSON:

    Code:
    {
        codebooks: '/rules/codebooks'
    }
    Given I know that Codebook is that start of the model hierarchy, I now know where to get a list of all codebooks. So lets fetch that list:

    Code:
    {
        codebooks: [{
                id: 1
                name: 'Football',
                description: 'A codebook about football',
                facets: '/rules/codebooks/1/facets/'
            }, {
                id: 2
                name: 'Basketball',
                description: 'A codebook about basketball',
                facets: '/rules/codebooks/2/facets/'
            }]
    }
    I also know that a Facet belongs to a Codebook and that a Codebook has many Facets. The RESTUful application tells us where to fetch the list of Facets for each Codobook instance, so lets get the Facets for the codebook with id 1.

    Code:
    {
        facets: [{
            id: 1
            name: 'How',
            description: 'A facet about how',
            codebook_id: 1,
            foci: '/rules/codebook/1/facets/1/foci/'
        }]
    }
    And there we have the list of facets for codebook with id 1. If I was being completely RESTful I'd also add a codebook property for each facet with the URL to get back up to the owning codebook.

    The question I have is why can't I configure my RESTful models in Ext 4 given 1 URL, the complete model hierarchy and additional configuration for each model telling it what property to search for to retrieve its list URL in its parent object (IE codebooks on the start url and facets for each codebook). Why can't stores fetch associations using a callback system instead of the user having to return data for an entire model hierarchy to access associations when the store initially loads? Why can't I configure a store for my Facet model (for example) by passing in a instance of a Codebook model object or just a codebook id and let Ext walk the resource tree?

    This post might sound like I am complaining. I don't intend it to sound that way. RESTful applications are so simple, they practically design themselves. If Ext 4 could handle the model side of RESTful applications the way I describe then it would make my life (and possibly a whole bunch of others) a whole lot easier and it might even encourage other developers to re-think their current designs and consider a RESTful approach. Having Tree widgets that can span models would also be extremely useful (but I expect that would come with having a store that can do the same).

    EDIT: We already know what property to look for on the parent object to fetch the list for a model via the name config on the hasMany association.

  2. #2
    Sencha User
    Join Date
    Aug 2008
    Posts
    51
    Vote Rating
    7
    TonySteele is on a distinguished road

      0  

    Default


    Feedback on this from Sencha ?
    I was assuming that Rest would work as described in this thread.

  3. #3
    Sencha - Community Support Team edspencer's Avatar
    Join Date
    Jan 2009
    Location
    Palo Alto, California
    Posts
    1,939
    Vote Rating
    7
    edspencer is a jewel in the rough edspencer is a jewel in the rough edspencer is a jewel in the rough

      0  

    Default


    This sounds like a pretty custom implementation. I would like to hear from anyone else who is following this pattern as I haven't seen it come up before...
    Ext JS Senior Software Architect
    Personal Blog: http://edspencer.net
    Twitter: http://twitter.com/edspencer
    Github: http://github.com/edspencer

  4. #4
    Ext JS Premium Member rstuart's Avatar
    Join Date
    Jan 2008
    Location
    Brisbane, Australia
    Posts
    140
    Vote Rating
    4
    rstuart is on a distinguished road

      2  

    Default


    Quote Originally Posted by edspencer View Post
    This sounds like a pretty custom implementation. I would like to hear from anyone else who is following this pattern as I haven't seen it come up before...
    Really? The described situation is exactly how RESTful applications are meant to function. Any other implementation that claims to be a RESTful interface isn't adhering to the definition of RESTful interface. There are many good books on the topic but for the purpose of this discussion the wikipedia article is sufficient to get an overview. Pay particular attention to the "Guiding principles of the interface" section. I suspect that most of the RESTful interfaces you've seen edspencer fail the HATEOAS principle which stipulates that the RESTful interface must provide a way to access related resources via a URI in the case of a RESTful interface which uses HTTP as its uniform interface.

    An application that provides a proper RESTful interface is very easy to work with. Unfortunately this hasn't been the case when you add ExtJS into the mix. Ultimately I have had to write my own data library in JavaScript and provide ways to transform chunks of it into something an ExtJS Store could understand. I had high hopes that this would be over in ExtJS 4. I got a little concerned when there was a reference to the REST URL microformat in some of the ExtJS 4 blog posts. That microformat is in my opinion redundant. All it does is remind people what HTTP verbs correspond to with respect to the traditional CRUD web app, regurgitates the HTTP response codes and then goes on to define a url system which defines what response you will receive back, something that should be done using the HTTP Accept header and not pre-formatted URLs. It also defines what URLs should look like (i.e. if all users are at /users then user with id 1 should be at /users/1). Such a provision is pointless with a proper RESTful interface which describes all its resources with associated URIs as stipulated by HATEOAS and demonstrated in my example above.

  5. #5
    Sencha User atian25's Avatar
    Join Date
    Oct 2008
    Location
    china
    Posts
    114
    Vote Rating
    2
    atian25 is on a distinguished road

      0  

    Default


    +1 for this, current extjs mvc is hard to reuse.
    @from: china
    @web: http://atian25.iteye.com
    @extensions: (extjs 4.x)
    * Ext.ux.grid.plugin.RowEditing - add some usefull features (v1.4 updated 2011-09-11)
    * Ext.ux.button.AutoRefresher
    * Ext.ux.form.field.DateTime

  6. #6
    Ext JS Premium Member
    Join Date
    Feb 2011
    Location
    Leverkusen, Germany
    Posts
    3
    Vote Rating
    0
    mc-h is on a distinguished road

      0  

    Default


    I too would love to see this in ExtJS, so +1.
    However it is true many developers don't follow this pattern even though it is standard

  7. #7
    Sencha User
    Join Date
    May 2011
    Location
    Oslo
    Posts
    7
    Vote Rating
    0
    espeak is on a distinguished road

      0  

    Default


    +1 for proper RESTful support

  8. #8
    Sencha User
    Join Date
    Oct 2010
    Posts
    11
    Vote Rating
    0
    pef is on a distinguished road

      0  

    Default


    +1
    Sadly, this answers the question I had in mind while searching the forum.
    Just like you and the others, I'd like to implement a RESTful service with an extjs UI.

    It's been several months since your post but if you're still around, can you comment on why you had to write your own data library in JavaScript ?

    I'm only starting with extjs, and I still intend to implement a REST service, but I guess the way to go would be to roll my own TreeStore (inheriting from the base one) : what's wrong with this approach ? What kept you from doing that ?

    Maybe I'm missing something obvious and that's all I seek with this question : as I said, I'm only starting looking into all this.

  9. #9
    Sencha - Community Support Team edspencer's Avatar
    Join Date
    Jan 2009
    Location
    Palo Alto, California
    Posts
    1,939
    Vote Rating
    7
    edspencer is a jewel in the rough edspencer is a jewel in the rough edspencer is a jewel in the rough

      0  

    Default


    @rstuart do you have some time to jump on a skype call so we can talk this one through?
    Ext JS Senior Software Architect
    Personal Blog: http://edspencer.net
    Twitter: http://twitter.com/edspencer
    Github: http://github.com/edspencer

  10. #10
    Ext JS Premium Member
    Join Date
    Feb 2011
    Location
    Saarbr├╝cken, Germany
    Posts
    11
    Vote Rating
    0
    s.busch is on a distinguished road

      0  

    Default


    +1

    I'm revisiting this thread and see now that @edspencer showed up here two days ago.

    Any news on this?

    We are looking for a real RESTful url capability, too.

    E.g.

    /contacts -> list of contacts
    /contacts/13 -> contact with id 13
    /contacts/13/notes -> notes of contact with id 13
    /contacts/13/notes/454 -> note with id 454 of contact

    ... just to get the idea. Maybe there could be a better design but even a bad RESTful design is currently impossible with the current "Rest"Proxy.

    Currently we have only "flat" urls as a replacement:

    /contacts
    /contacts/13
    /notes?contactid=13
    /notes/454?contactid=13

    (from memory, may be a little different in real application)

    which doesn't work well from an API design perspective, escpecially the last URL has a bad code smell.

    @edspencer, I found these slides quite helpful: http://www.slideshare.net/Wombert/phpny-urls-rest


    Sebastian