Chapter 7. Communicating with the server

 

This chapter covers

  • The server’s role in an SPA environment
  • How MV* frameworks communicate with the server
  • Handling results with callback functions and promises
  • Consuming RESTful services

In chapter 1, you learned how the adoption of the XMLHttpRequest (XHR) API and the AJAX movement eventually led to the emergence of SPAs. After XHR was supported in the browser—as a COM component at first and then natively—developers could use it to asynchronously load both the application’s scaffolding and its data without refreshing the page. This opened many new avenues for the ways that web pages could be constructed.

Until now, you’ve been focusing on creating the SPA itself. In doing so, you’ve used XHR to dynamically retrieve the templates used to construct your views but restricted the data in your sample applications to local stub data. In this chapter, you’ll take another important step forward. You’re going to move the source data to the server and learn how to remotely access it from your SPA.

We’ll kick things off with a brief look at the communication process between the SPA client and the server. After you’re clear on the overall process, we’ll look at the details of what happens on the client.

7.1. Understanding the project requirements

7.2. Exploring the communication process

7.3. Using MV* frameworks

7.4. Consuming RESTful web services

7.5. Project details

7.6. Chapter challenge

7.7. Summary