11 Breaking barriers with custom APIs and webhooks

 

This chapter covers

  • Creating custom API endpoints and hosting them as cloud functions
  • Creating and calling APIs to extend Hugo’s core functionality
  • Adding compile-time LaTeX
  • Hooking up webhooks with APIs to automate manual tasks

APIs are marvelous. We can encapsulate the most complicated functionality behind an easy-to-use API, and its users don’t need to know the logic or the details of how an API works. Chapter 9 went over some APIs provided by third parties, which worked for us. But it is not always possible to get APIs for everything we need. Some functionality might be particular to our website or be our secret sauce. We need to write this ourselves. The Jamstack identifies that as a valid and practical use case and provides support for this functionality.

In this chapter, we will go over some of the means that the Jamstack provides to handle cases where Hugo might not have the features we need (figure 11.1). We will embed LaTeX-based math inside our project—the Jamstack way—compiled during the build and delivered without any excess JavaScript or additional network request. The conversion from textual to a visual representation of the mathematics will be done outside Hugo and integrated into the web page at build time. We will also look at the concept of webhooks and how we can use them to link together independent services.

11.1 Building custom APIs

11.1.1 Choosing the layer of the application stack

11.1.2 Monoliths vs. microservices

11.2 Adding LaTeX rendering to our website

11.2.1 What is LaTeX?

11.2.2 How can we render LaTeX?

11.2.3 Server-side LaTeX rendering

11.2.4 Writing the code to render LaTeX

11.2.5 Adding a HTTP server to call this function

11.2.6 Adding some security to prevent unauthorized access

11.2.7 Deploying to the cloud via Netlify Functions

11.2.8 Deploying to the cloud via Heroku