HTTP Protocol

HTTP Chapters

What is Protocol

What is Protocol ?

Protocol are standard set of rules that enable two devices to connect and transmit data or exchange information to one another.

In short, protocol is a common language used by clients and servers to interact and exchange data.

Each protocol has its own method or mechanism as how data is formatted,when it has to be sent and what to do with it once received, how that data is compressed or how to check for errors in data.

Few Examples of commonly used Internet protocols are FTP (File Transfer Protocol),HTTP (Hypertext Transfer Protocol), TCP/IP (Transfer Control Protocol/Internet Protocol), SMTP (Simple Mail Transfer Protocol) ,POP ( Post Office Protocol ) and many more.

Types of Protocol

Types of Protocol 

There are two types of protocol namely

  1. Stateless protocol
  2. Stateful protocol
Stateless Protocol:

In case of stateless the data transmitted is not modified from one device or system before sending to another system.

We mean to say In Stateless the data exchanged between client & server is not altered.

Example: UDP, IP, HTTP etc

In stateless protocol there is no record of the state is saved at server end. Client send request to the server and server response back according to current state.
A stateless server does not keeps state between connections. So, When we send a request to a stateless server, it does not create any objects that track information regarding your requests.

Statefull Protocol:

In case of stateful the data transmitted is modified from one device or system before sending to another system.

We mean to say In Stateful the data exchanged between client & server is altered .

In stateful protocol there is tight dependency between client and server . If client send a request to the server then it expects some kind of response, if it does not get any response then resend request.

A stateful server keeps state of connections

Example: FTP, Telnet etc

Note: For Developing Client Server applications using J2EE Technologies we use HTTP ( Stateless Protocol)

What is HTTP

What is HTTP Protocol

HTTP is a protocol which allows servers and clients to exchange data on internet.

It is standard stateless protocol for exchange of data between client browsers & Web Server

Whenever a client through browser requests a file placed at server, the server responds to client’s request through HTTP.

In HTTP, it’s always the client who initiates an interaction by establishing a connection and sending an HTTP request. If the server is available, the server will respond to clients request otherwise the client or server can immediately terminate the connection.

Example:

when we are using a web browser we can click the Stop button on your browser to stop the download process, effectively closing the HTTP connection with the web server.

HTTP 1.1 standard is currently used for exchanging data across web.

HTTP is an asymmetric request-response client-server protocol .

An HTTP client sends a request message to an HTTP server. The server, in turn, returns a response message.

In other words, HTTP is a pull protocol, the client pulls information from the server (instead of server pushes information down to the client).

HTTP Architecture

HTTP Request-Response Process Architecture:

Whenever you issue a URL from your browser to get a web resource using HTTP, e.g. http://www.anysite.com/index.html, the browser turns the URL into a request message and sends it to the HTTP server. The HTTP server interprets the request message, and returns you an appropriate response message, which is either the resource you requested or an error message.

This process is illustrated below:

Uniform Resource Locator (URL):

A URL (Uniform Resource Locator) is used to uniquely identify a resource over the web. URL has the following syntax:

protocol://hostname:port/path-and-file-name

There are 4 parts in a URL:

  • Protocol: The application-level protocol used by the client and server, e.g., HTTP, FTP, and telnet.
  • Hostname: The DNS domain name (e.g www.anysite.com) or IP address (e.g  192.128.1.2) of the server.
  • Port: The TCP port number that the server is listening for incoming requests from the clients.
  • Path-and-file-name: The name and location of the requested resource, under the server document base directory.

For example, in the URL http://www.anysite.com/docs/index.html, the communication protocol is HTTP; the hostname is www.anysite.com. The port number was not specified in the URL, and takes on the default number, which is TCP port 80 for HTTP. The path and file name for the resource to be located is “/docs/index.html“.

Other Examples:

ftp://www.ftp.org/docs/test.txt
mailto:user@anysite.com
telnet://www.anysite.com/

HTTP Request

HTTP Requests:

An HTTP transaction begins with a request from the client browser and ends with a response from the server.

An HTTP request consists of three components:

  • Method——URI—Protocol/Version
  • Request headers
  • Entity body

HTTP Response

HTTP response is the result send by server to client request.

HTTP response also consists of three parts:

  • Protocol—Status code——Description
  • Response headers
  • Entity body