Chapter 15. REST APIs and JSON

While we saw some REST API examples in Chapter 8, our paradigm so far has mostly been “process the data on the server side and send formatted HTML to the client.” Increasingly, this is not the default mode of operation for web applications. Instead, most modern web applications are single-page applications (SPAs) that receive all of their HTML and CSS in one static bundle and then rely on receiving unstructured data as JSON and manipulating HTML directly. Similarly, the importance of posting forms to communicate changes to the server is giving way to communicating directly using HTTP requests to an API.

So it’s time to turn our attention to using Express to provide API endpoints instead of preformatted HTML. This will serve us well in Chapter 16, when we demonstrate how our API could be used to dynamically render an application.

In this chapter, we’ll strip down our application to providing a “coming soon” HTML interface: we’ll fill that in in Chapter 16. Instead, we’ll focus on an API that will provide access to our vacation database and provide API support for registering “out of season” listeners.

Web service is a general term that means any application programming interface (API) that’s accessible over HTTP. The idea of web services has been around for quite some time, but until recently, the technologies that enabled them were stuffy, Byzantine, and overcomplicated. There are still systems that use those technologies (such as SOAP and WSDL), ...

Get Web Development with Node and Express, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.