Any app you access through your web browser is a web app. Years ago, we used desktop apps installed on our computers for almost anything we were doing. With time, most of these apps became accessible via a web browser. Accessing an app in a browser makes it more comfortable to use. You don’t have to install anything, and you can use it from any device that has access to the internet, such as a tablet or smartphone.

ihf2w6lf.bmp

A web app is composed of two parts:

n1u5rgid.bmp

A web browser uses a protocol named Hypertext Transfer Protocol (HTTP) to communicate with the server over the network. This protocol accurately describes how the client and the server exchange data over the network.

What you need is not only something that understands HTTP, but something that can translate the HTTP request and response to a Java app. This something is a servlet container (sometimes referred to as a web server): a translator of the HTTP messages for your Java app. This way, your Java app doesn’t need to take care of implementing the communication layer. One of the most appreciated servlet container implementations is Tomcat, which is also the dependency we’ll use for the examples in this book.

gkjppk5h.bmp

What is a servlet? A servlet is nothing more than a Java object that directly interacts with the servlet container. When the servlet container gets an HTTP request, it calls a servlet object’s method and provides the request as a parameter. The same method also gets a parameter representing the HTTP response used by the servlet to set the response sent back to the client that made the request.

We’ll use a servlet with the Spring apps we develop with Spring, but you won’t need to write this yourself, so you don’t have to focus on learning to implement servlets.

7jhgjees.bmp

Spring Boot

To create a Spring web app, we need to configure a servlet container, create a servlet instance, and then make sure we correctly configure this servlet instance such that Tomcat calls it for any client request.

Spring Boot is now one of the most appreciated projects in the Spring ecosystem. It helps you create Spring apps more efficiently and focus on the business code you write by eliminating a huge part of the code you used to write for configurations.

The following list summarizes the steps we’ll take to create the Spring Boot project using start.spring.io:

  1. Access start.spring.io in a web browser.
  2. Select the project properties (language, the version, the build tool, Maven or Gradle, and so on).
  3. Select the needed dependencies you want to add to your project.
  4. Use the Generate button to download the archived project.