Chapter 4. Using the blueprint API
This chapter covers
- Expanding your understanding of the relationships among requests, routes, and actions in a Sails API
- Generating a backend API with blueprint routes and blueprint actions
- Integrating frontend requests with the blueprint API
- Using blueprint shortcut routes to access data from the browser
- Upgrading with WebSockets to provide realtime features
Chad loved Brushfire’s ability to display and add YouTube videos. He soon discovered, however, the limitations of the simulated backend. When he refreshed his browser, all of the videos he added were no longer listed! We explained that this was because the links to the YouTube videos he added were stored temporarily in an array in memory. When he refreshed the browser, the array returned to its original state without his additional links in the list. Chad wasn’t happy about this. Fortunately, we had anticipated this problem and had begun work on a true backend API that would store the added video links in a database. The next time Chad added a hundred videos to Brushfire (oops!), they’d still be there when he refreshed his browser. Let’s see how we added this functionality to Brushfire.