Working with the Hyperlink API (REST) ​​on the backbone

In the process of creating Backbone.js SPA, which speaks with the RESTful API (hopefully). I tried to develop an API around resources using hypermedia to link resources together. Since I started implementing things in Backbone, I am beginning to realize that doing true hypermedia with Backbone may not be very good.

The main problem is the basic routers, which want their paths announced in advance. With a good Hypermedia API, resource URIs do not have to be hardcoded in the client to provide flexibility when adding new features and (blanking out) changes to resources.

I'm playing with the idea of decoupling resource page on the level of resources API-level . Someone screams if it's nuts. Basically, this would mean defining resource paths in my base application (I think a discrete page), which would then retrieve one or more API level resources.

This leads to some interesting questions:

  • Is that even a good idea? Do I have to do my best to reuse the API level resource URIs in my application so that the routes are from 1 to 1.

    • I understand that a page and an api object are just different representations of the same resource, but in most cases a page is a collection of several resources. Or am I just crazy :)
  • What happens with updating pages in the middle of a series of navigation. How do I know the location of API level resources if they do not match?

  • It seems to me that the RESTful design emphasizes the discovery over understanding the things ahead. Am I guessing it right? What is code loading? Can someone point me to further reading if I go in the right direction.

Most resources are read-only, so use only the GET verb, but I have a few scripts that use POST / PUT (DELETE really is not in the domain of this particular client, except, perhaps, interrupting the order before it is placed completely).

* , REST. , , . .

Edit:

SPA. :

  • URI API , ( ). :

    // this object downloaded along with the application code, on a refresh
    Framework.API.Resources = {
        Tasks: {
            uri: '/tasks',
            rel: 'self'
        },
        Users: {
            uri: '/users',
            rel: 'self'
        },
        // ... etc
    }
    
    // then in a collection
    
    var TaskCollection = Backbone.Collection.extend(
        uri: Framework.API.Resources.Tasks.uri
        // implementation details
    );
    
  • , "root" uri . , Backbone.Router.route, , " ". - ?

+5
2

Re # 3

, .

.  1) , . , , , HTML .  2) . , , , . , , .

, . , API REST. API , . . , , .

, 1-1 . REST , β†’ , -. , 1-1, .

+1

REST, , , , Backbone.js. , , javascript, , , . Hypermedia Backbone.js

0

All Articles