chapter eight

8 The web stack

 

This chapter covers:

  • the construction of a edge-service and a public API,
  • the Vert.x web client,
  • JSON web tokens and cross-origin resource sharing,
  • serving and integrating a Vue.js reactive application with Vert.x,
  • testing an HTTP API with REST Assured.

The Vert.x web stack provides many tools to build web application backends. This includes advanced routing, authentication, a HTTP client, and more. This chapter will guide you through exposing a HTTP API with JSON web tokens (JWT) for access control, making HTTP requests to other services, and building a reactive single-page application that connects to the HTTP API.

Note

This book does not cover the following noteworthy elements from the Vert.x web stack that are not needed to build the application in part 2: routing with regular expressions, cookies, server-side sessions, server-side template rendering and cross-site request forgery protection. You can get more details in the official documentation at vertx.io/.

8.1  Exposing a public API

Let us start with a reminder of what the public API service does, as illustrated in figure 8.1.

Figure 8.1. Public API overview
public api

8.1.1  Routing HTTP requests

8.1.2  Making HTTP requests

8.2  Access control with JWT tokens

8.2.1  Using JWT tokens

8.2.2  What is in a JWT token?

8.2.3  Handling JWT tokens with Vert.x

8.2.4  Issuing JWT tokens with Vert.x

8.3  Cross-origin resource sharing (CORS)

8.3.1  What is the problem?

8.3.2  Supporting CORS with Vert.x

8.4  A modern web frontend

8.4.1  Vue.js

8.4.2  Vue.js application structure and build integration

8.4.3  Backend integration illustrated