Summary
This chapter introduces HTTP networking, which is often used to connect to RESTful web services from within Java applications. HTTP is a textual request-response protocol. A client sends a request to a server and then gets a response. Each HTTP request has a method; for instance, you would use the GET request to retrieve data, POST to send data, and so on. In Java applications, you will often send and receive text in JSON format.
The HttpUrlConnection
class provides the primary way to make HTTP requests. Your code writes to an output stream to send data, then reads the response from an input stream. The open-source jsoup library provides a convenient API to retrieve and parse HTML data. Starting with Java 11, you can use the java.net.http
module for a more modern Reactive Streams approach to HTTP networking. In the next chapter, you'll learn about certificates and encryption—both commonly used with HTTP networking.