Chapter 8. Building a single-page JavaScript application with JSON
This chapter covers
- Defining a RESTful web service
- Sending JSON to the web browser
- Parsing JSON from an HTTP request
- Converting between JSON data and Scala objects
- Validating JSON data
- Authenticating JSON web service requests
In this chapter, we’re going to reimplement part of the sample application from chapter 2 using a more modern JavaScript client application architecture that allows you to make more responsive web applications with richer and more interactive user interfaces.
We’re going to use Play to build the server for a JavaScript application that runs in the browser. Instead of using view templates to generate HTML on the server and send web pages to the browser, we’re going to send raw data to the web browser and use JavaScript to construct the web page.
Our goal is to reimplement the product list application so that we can edit product information in place by editing the contents of an HTML table, and have changes saved to the server automatically, without submitting a form.
Figure 8.1 shows a table of products that allows us to edit values by clicking and typing, adding uncoated to the first product’s description in this case.