O'Reilly logo

Full Stack Web Development with Backbone.js by Patrick Mulder

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 8. Basic API Concerns

In the last chapter, you used an API that was “canned” to learn about populating a collection with fetch(). While Backbone.js is backend agnostic, you could work with any programming language or data store to build a “real” application stack. However, with the advances of Node and JavaScript, some of the concepts that apply to Backbone at the client equally apply when building APIs or connecting to data stores at the server.

Even if your use case does not require an isomorphic application design, where logic for e.g. templating and data validation can be shared, the concepts of this chapter should help you understand more enhancements of Backbone models and collections to “write” state to a remote server.

To persist state with Backbone, we delve deeper into concepts from API development. This is why this chapter on general persistence, and the next chapter on authentication, move the development of Munich Cinema more and more towards full stack JavaScript application development.

Our discussion on fetching movies is extended to storing votes on movies. In general, changing application state also requires discussion on authenticating users. But to simplify the discussion in this chapter, we let users vote on movies without authentication. Then, in the next chapter, authentication will be discussed.

To store state from the client at a server, we first replace the mock API with a Movies API based on Restify and JavaScript promises based on Bluebird. We then ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required