Creating a Gateway API

What is a Gateway API? It's a one-stop facade where we can make all our various web requests. The facade then dispatches the requests to the proper backend service based on the configuration settings.

In our case, we don't want the browser talking to two different ports. Instead, we'd rather serve up a single, unified service with different URL paths.

In Chapter 16, Microservices with Spring Boot, we used Spring Cloud for several microservice tasks, including service discovery, circuit breaker, and load balancing. Another microservice-based tool we will make use of is Spring Cloud Gateway, a tool for building just such a proxy service.

Let's start by adding this to our chat microservice:

 compile('org.springframework.cloud:spring-cloud-starter-gateway') ...

Get Developing Java Applications with Spring and Spring Boot 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.