...

/

Hypertext Transfer Protocol (HTTP)

Hypertext Transfer Protocol (HTTP)

Learn about the Hypertext Transfer Protocol (HTTP) and its importance in APIs.

Introduction

The Hypertext Transfer Protocol (HTTP) is a statelessA stateless protocol is one in which each request is considered independent of any other request. This makes it simple to implement., application-layer protocol for distributed and hypermedia information systems. It's the foundation of data communication for the World Wide Web and is considered the de facto standard for client-server resource sharing. Web servers and client applications (browsers) must adhere to the message formats and transmission methods provided in the HTTP specifications. For instance, when we type a URL into a browser, the web server receives an HTTP request directing it to fetch and deliver the specified web page.

HTTP is based on the concepts of request and response, where one program (the client) requests another program (the server), and the server returns a response. The client usually makes requests in the form of HTTP commands, and the server responds with data in the form of documents. These commands are structured by different API architecture styles that we'll discuss in the coming chapters. Because it’s a driving force for APIs, HTTP is an essential protocol to understand.

As long as the request conforms to HTTP standards, the server will respond with the requested resources, regardless of the type of client.

This lesson discusses the essentials of HTTP. First, we explain its request and response formats. Next, we look into the HTTP methods, response status codes, and different HTTP headers. Toward the end, we discuss the significance of HTTP in APIs. Finally, we explain the secure version of HTTP, which is HTTPS.

HTTP message flow

As discussed in the previous section, HTTP communication is initiated by the clients sending a request to the server, and the server responds. This section discusses the request and response message structure. The server parses each request to interpret the request and generate the response. In the same way, the client parses the received response from the server and collects the desired application data from the response message.

HTTP request structure

An HTTP request message is composed of the following four components:

  • Method: HTTP provides built-in methods that determine what kind of ...