HTTP Requests and HTTP Response

In this lesson, we will walk you through the concepts of HTTP request and response.

What is an HTTP request?

HTTP requests are the messages sent by the client to initiate an action on a resource identified by a given URL over the network. There are various HTTP request methods for specific purposes.

The components of an HTTP request are as below:

  • The method to be applied to the resource – an HTTP method (like GET, PUT, POST HEAD or OPTIONS), that describes the action to be performed. We have already discussed the various HTTP methods in the previous lesson.

  • The resource identifier – resource identified by a given request URL.

  • Headers (optional) – headers are the information sent to the server in the form of key/value pairs, which contains the details of what the browser wants and will accept from the server.

  • Params (optional) – used for sending additional data to the server. For example, a query parameter.

  • Message body (optional) – These are additional information required by the server to process current requests properly. For example, a file type of JSON or XML sent in the case of a POST or PUT method request.

What is an HTTP response?

After receiving and processing an HTTP request message, a server responds with an HTTP response message.

HTTP request and response example

The example below will help you to understand more about HTTP request and response.

Request – The request below contains the HTTP Method, the target URL, and the query Param in the URL (post id = 1).

curl -iX GET  https://jsonplaceholder.typicode.com/posts/1

Get hands-on with 1400+ tech skills courses.