Hypertext Transfer Protocol (HTTP) Interview Preparation Guide
Download PDF

Hypertext Transfer Protocol (HTTP) is a networking protocol for distributed, collaborative, hypermedia information systems. HTTP is the foundation of data communication for the World Wide Web. The standards development of HTTP has been coordinated by the Internet Engineering Task Force (IETF) and the World Wide Web Consortium, so learn HTTP to get preparation for a web based job with the help of this HTTP interview questions and answers guide

44 HTTP Questions and Answers:

Table of Contents:

HTTP Interview Questions and Answers
HTTP Interview Questions and Answers

2 :: Describe the different roles of HTTP?

In HTTP, there are two different roles: server and client. In general, the client always initiates the conversation; the server replies. HTTP is text based; that is, messages are essentially bits of text, although the message body can also contain other media. Text usage makes it easy to monitor an HTTP exchange.

3 :: What is the mean of GET?

GET is the simplest type of HTTP request method; the one that browsers use each time you click a link or type a URL into the address bar. It instructs the server to transmit the data identified by the URL to the client. Data should never be modified on the server side as a result of a GET request. In this sense, a GET request is read-only, but of course, once the client receives the data, it is free to do any operation with it on its own side - for instance, format it for display.

4 :: What are response codes in HTTP?

HTTP response codes standardize a way of informing the client about the result of its request.
You might have noticed that the example application uses the PHP header(), passing some strange looking strings as arguments. The header() function prints the HTTP headers and ensures that they are formatted appropriately. Headers should be the first thing on the response, so you shouldn't output anything else before you are done with the headers. Sometimes, your HTTP server may be configured to add other headers, in addition to those you specify in your code.

5 :: What are status codes in HTTP?

In HTTP/1.0 and since, the first line of the HTTP response is called the status line and includes a numeric status code (such as "404") and a textual reason phrase (such as "Not Found"). The way the user agent handles the response primarily depends on the code and secondarily on the response headers. Custom status codes can be used since, if the user agent encounters a code it does not recognize, it can use the first digit of the code to determine the general class of the response.

6 :: Explain about persistent connections?

In HTTP/0.9 and 1.0, the connection is closed after a single request/response pair. In HTTP/1.1 a keep-alive-mechanism was introduced, where a connection could be reused for more than one request.

7 :: Explain secure HTTP?

There are currently two methods of establishing a secure HTTP connection: the https URI scheme and the HTTP 1.1 Upgrade header, introduced by RFC 2817. Browser support for the Upgrade header is, however, nearly non-existent, so HTTPS is still the dominant method of establishing a secure HTTP connection. Secure HTTP is notated by the prefix https:// instead of http:// on web URIs.

8 :: Explain request message in HTTP?

The request message consists of the following:
☛ Request line, such as GET /images/logo.png HTTP/1.1, which requests a resource called /images/logo.png from server
☛ Headers, such as Accept-Language: en
☛ An empty line
☛ An optional message body
The request line and headers must all end with <CR><LF> (that is, a carriage return followed by a line feed). The empty line must consist of only <CR><LF> and no other white-space. In the HTTP/1.1 protocol, all headers except Host are optional.
A request line containing only the path name is accepted by servers to maintain compatibility with HTTP clients before the HTTP/1.0 specification in RFC1945.

9 :: Tell me what is HTTP session state?

HTTP is a stateless protocol. A stateless protocol does not require the server to retain information or status about each user for the duration of multiple requests. For example, when a web server is required to customize the content of a web page for a user, the web application may have to track the user's progress from page to page. A common solution is the use of HTTP cookies. Other methods include server side sessions, hidden variables (when the current page is a form), and URL-rewriting using URI-encoded parameters, e.g., /index.php?session_id=some_unique_session_code.

10 :: What is Idempotent methods and web applications?

Methods PUT and DELETE are defined to be idempotent, meaning that multiple identical requests should have the same effect as a single request. Methods GET, HEAD, OPTIONS and TRACE, being prescribed as safe, should also be idempotent, as HTTP is a stateless protocol.

11 :: Tell me what happens to an undeliverable datagram?

An undeliverable datagram is discarded and an ICMP error message is sent to the source host.

12 :: Explain IP is a best-effort protocol in HTTP?

IP is a best-effort protocol, because it will make every effort to always transmit a datagram and also datagrams will not be just discarded. However, the delivery of the datagram to the destination is not guaranteed.

13 :: Tell me what do you mean by IP is an unreliable protocol?

IP is a unreliable protocol because it does not guarantee the delivery of a data-gram to its destination. The reliability must be provided by the upper layer protocols like TCP. IP does not support flow control, re-transmission, acknowledgement and error recovery.

14 :: Tell me to which OSI layer does IP belong?

IP belongs to the Network Layer (layer 3) in the OSI model.
internet protocol is working in network layer of osi model in congection with tcp tx layer protocol.

15 :: What is the mean of PUT?

A PUT request is used when you wish to create or update the resource identified by the URL. For example,
1 PUT /clients/robin
might create a client, called Robin on the server. You will notice that REST is completely backend agnostic; there is nothing in the request that informs the server how the data should be created - just that it should. This allows you to easily swap the backend technology if the need should arise. PUT requests contain the data to use in updating or creating the resource in the body. In cURL, you can add data to the request with the -d switch.
1 curl -v -X PUT -d "some text"

16 :: What is the mean of 500 Internal Server Error HTTP response codes?

When all else fails; generally, a 500 response is used when processing fails due to unanticipated circumstances on the server side, which causes the server to error out.

17 :: What is the mean of 409 Conflict HTTP response codes?

This indicates a conflict. For instance, you are using a PUT request to create the same resource twice.

18 :: What is the mean of 405 Method Not Allowed HTTP response codes?

The HTTP method used is not supported for this resource.

19 :: What is the mean of 401 Unauthorized HTTP response codes?

This error indicates that you need to perform authentication before accessing the resource.

20 :: What is the mean of 404 Not Found HTTP response codes?

This response indicates that the required resource could not be found. This is generally returned to all requests which point to a URL with no corresponding resource.

21 :: What is the mean of 400 Bad Request HTTP response codes?

The request was malformed. This happens especially with POST and PUT requests, when the data does not pass validation, or is in the wrong format.

22 :: What is the mean of 201 Created HTTP response codes?

This indicates the request was successful and a resource was created. It is used to confirm success of a PUT or POST request.

23 :: What is 200 OK HTTP response codes?

This response code indicates that the request was successful.

24 :: What is HTTP Client Libraries?

cURL is, more often than not, the HTTP client solution of choice for PHP developers.
To experiment with the different request methods, you need a client, which allows you to specify which method to use. Unfortunately, HTML forms do not fit the bill, as they only allow you to make GET and POST requests. In real life, APIs are accessed programmatically through a separate client application, or through JavaScript in the browser.
This is the reason why, in addition to the server, it is essential to have good HTTP client capabilities available in your programming language of choice.
A very popular HTTP client library is, again, cURL. You've already been familiarized with the cURL command from earlier in this tutorial. cURL includes both a standalone command line program, and a library that can be used by various programming languages. In particular, cURL is, more often than not, the HTTP client solution of choice for PHP developers. Other languages, such as Python, offer more native HTTP client libraries.

25 :: What is Representations in HTTP?

The HTTP client and HTTP server exchange information about resources identified by URLs.
We can sum up what we have learned so far in the following way: the HTTP client and HTTP server exchange information about resources identified by URLs.
We say that the request and response contain a representation of the resource. By representation, we mean information, in a certain format, about the state of the resource or how that state should be in the future. Both the header and the body are pieces of the representation.
The HTTP headers, which contain metadata, are tightly defined by the HTTP spec; they can only contain plain text, and must be formatted in a certain manner.
The body can contain data in any format, and this is where the power of HTTP truly shines. You know that you can send plain text, pictures, HTML, and XML in any human language. Through request metadata or different URLs, you can choose between different representations for the same resource. For example, you might send a webpage to browsers and JSON to applications.