State the core components of an HTTP response ?
Last Updated :
20 Sep, 2021
Have you ever thought about how the front-end of an application communicates with the backend to get data or perform certain operations? It is done through API Requests. API stands for Application Programming Interface. The communication between our client and the API is achieved using HTTP Request which is followed by a Response to the client. Both the Requests and Response follows a certain syntax and structure to ease the communication process.
Whenever our client application wants to communicate to the server, it sends out a message to the server using HTTP Protocols, which is also termed as the HTTP Request. Based on that message, the server performs certain operations as demanded by the message and then replies to the client through a message, also knows as HTTP Response.
Below is an image depicting the Request-Response Cycle:
Image of HTTP Request-Response Cycle
Structure of HTTP Response: As discussed above, the HTTP Response has a special structure that is followed so that the client can easily understand it. There exists a Universal Language that everybody follows so that there is no communication gap between people. HTTP Response broadly has 3 main components:
- Status Line
- Headers
- Body (Optional)
An HTTP Response as a whole looks like the below picture:
Anatomy of HTTP Response
Let us go through each of them one by one:
Status Line: An example of a Status-Line is given below:
HTTP/1.1 200 OK
The Status Line contains three important components - HTTP Version, HTTP Response Code, and a Reason-Phrase.
- HTTP Version: The HTTP version number shows the HTTP specification to which the server has tried to make the response message comply. In the above example, 1.1 is the HTTP Version.
- HTTP Response Code: It is a 3 digit number that shows the conclusion of the Request. In the above example, the response code 200 denotes that the content requested was OK. A very popular Status Code that we frequently encounter is 404 which represents the requested resource was not found.
- Reason-Phrase: Also known as Status Text as it summarizes the Status Code in human-readable form.
Response Header: The Response Header contains the information about the content that is being returned in response together with data about the Server that sent it. This information helps the Client/Browser in deciding in what way the response data would be used. In other words, headers can be said as metadata that is sent together with a response to provide more info about it.
The Server can send as many headers as needed. The headers are sent as a key-value pair separated by a colon ( : ). Although the server can send as many headers as required, the most popular response headers are Content-Length, Content-Type, Date, Server, Set-Cookie, etc.
Date: Thu, 16 Jan 2016 08:16:18 GMT
Server: IBM_CICS_Transaction_Server/3.1.0(zOS)
Content-type: image/jpg
In the above example, the response header shows the date and time when the response was sent, the server that sent the response, and the type of content that was sent, which here is a jpg image file.
Body: In case of a successful response, the body of the Response Message is used to serve the Client/User with the resource asked for in the request. Although the body is optional, it is one of the most fundamental parts of the communication between the Client and Server and is sent most of the time. The body carries the data and can be in one of the many formats such as json, html, image, etc. which is accordingly specified in the headers.
In case of some errors, the body might provide the reason for the errors or the actions needed to complete the request successfully. Sometimes, it may have a link to guide the user to some other page.
Similar Reads
HTTP status codes | Client Error Responses
The browser and the site server have a conversation in the form of HTTP status codes. The server gives responses to the browserâs request in the form of a three-digit code known as HTTP status codes. The categorization of HTTP status codes is done in five sections which are listed below. Information
4 min read
What are the components of System Design?
The process of specifying a computer system's architecture, components, modules, interfaces, and data is known as system design. It involves looking at the system's requirements, determining its assumptions and limitations, and defining its high-level structure and components. The primary elements o
10 min read
HTTP status codes | Server Error Responses
HTTP status codes is a conversation between your browser and the site server. The server gives responses to the browser's request in the form of a three-digit code known as HTTP status codes. Categories of HTTP status codes are. Informational responses (100â199) Successful responses (200â299) Redire
3 min read
HTTP status codes | Redirection Responses
HTTP status codes are a conversation between your browser and the site server. The server gives responses to the browser's request in the form of a three-digit code known as HTTP status codes. The HTTP status codes are categorized into five sections which are listed below. Informational responses (1
2 min read
Which HTTP response status codes result in then() and which in catch() ?
Axios is a popular JavaScript library for making HTTP requests. It uses promises to handle the response from the server, and provides a convenient then() and catch() syntax for working with the data or handling errors. Have you ever wondered which HTTP response status codes will cause axios to call
4 min read
Difference Between Software Components and Connectors
In the field of software architecture and design, it is essential to comprehend the basic components of a system. Software components and connections are two essential ideas that are crucial to this field. These components serve as the foundation for the organization, communication, and functionalit
4 min read
Router Components, Boot Process, and Types of Router Ports
A router is a network device that forwards information packets among PC networks. Routers perform traffic routing functions on the Internet. Data sent over the Internet, such as a website or email, is in the form of data packets. Packets are typically forwarded from one router to another through the
5 min read
HTTP status codes | Informational Responses
The HTTP status codes are used to indicate that any specific HTTP request has successfully completed or not. The HTTP status codes are categorized into five sections those are listed below: Informational responses (100â199) Successful responses (200â299) Redirects (300â399) Client errors (400â499) S
2 min read
Can you console all HTTP status code in Node.js ?
NodeJS is a runtime environment built to run Javascript outside the browser. It is widely used to build servers at the backend, which interact with the frontend such as websites, mobile applications, and many more. In this article, We will check whether we can console all HTTP status codes in NodeJS
3 min read
Components of Search Engine
A search engine typically comprises several key components that work together to index, retrieve, and present relevant information to users. Here are the main components of a search engine: Table of Content 1. Web Crawling Component of Search Engine:2. Indexing Component of Search Engine:3. Ranking
15+ min read