AI Hints
Home›Spring Boot Tutorial›What Spring Boot Is, Where Spring Boot Is Used and How a Web App Works
Spring Boot · Lesson 3 of 120

How a Web App Works

Requests and responses.

⏱ 2 min read▶ Video at 2:42🎓 Free
Watch this lesson in the Spring Boot courseWatch on YouTube ↗Full Spring Boot course

Before we write more code, let's understand how a web app talks. It's a simple conversation, of requests and responses.

  • A conversation
  • Requests
  • Responses

One request, one response

A client, like a browser, or a phone app, sends a request. The request travels over the network, to a server. The server finds the right code to run. That code builds a response. And the response travels back to the client.

  1. Client sends a request
  2. Over the network
  3. Server finds the code
  4. Code builds a response
  5. Client gets the response

Words to know

The client is the program that asks. The server is the program that answers, and that's what we'll build. A URL says where to send the request, like localhost colon eight zero eight zero slash books. Localhost means this computer, and eight zero eight zero is the port, the door our server listens on.

keyvalue
Clientasks (browser, app, curl)
Serveranswers (our Spring app)
URLlocalhost:8080/books
Port8080, the door we listen on

A request for books

This controller answers requests for slash books. It returns a list of three titles. Spring turns the list into JSON, a text format for data, before sending it. Run it. Curl is our client, and asks for slash books. The server answers with the three titles, as a JSON list.

BookController.javajava
@RestController
public class BookController {

    @GetMapping("/books")
    public List<String> books() {
        return List.of("Dune", "The Hobbit", "Circe");
    }
}
Output
["Dune","The Hobbit","Circe"]
Also uses _curl.sh
curl localhost:8080/books

Summary

A client sends a request to a URL, the server runs the matching code, and sends a response back. Next, what you need to install.

Key takeaways
  • Request → server
  • Server → response
  • localhost:8080
Next up: What You Need — tools for this course