The HTTP request is the backbone of Web Development. It's the way users interact with the application on the web server. Read this article to understand everything about the HTTP Requests.
What is an HTTP Request
When you open a website through the web browser the web browser sends an HTTP Request to the web server hosting the application. The request is created using the HTTP Protocol. Upon receiving the HTTP request, the web application responds with an HTTP response which contains usually is the web page you requested
How does an HTTP Request look like
Let's examine an HTTP request to a website:
GET / HTTP/1.1 Host: www.noodles.dev
The first line contains the request verb, the request URI and the protocol version.
The request verb can be one of the following:
- GET: The Get method retrieves data from the server, as its name implies. Furthermore, it is the most widely used method without a request body. The Get request fires every time you open a website to retrieve its contents. In addition, it is the same as the read operation.
- HEAD: The Head method is similar to Get, but it only retrieves the header data rather than the entire response body. We also use it when we need to check the file size of a document without having to download it.
- POST: The Post method is used to send information to a server. Using the Post request, you can add or update data. In the request body, we send the information that needs to be updated. In the real world, the Post request is used to update the form data on a website.
- PUT: Because it updates the data, the Put method is similar to the Post method. Only difference is that we use it when we need to completely replace an existing entity. PUT methods are also idempotent, which means they always return the same result when called repeatedly.
- PATCH: This method is similar to Post and Put, but it's used when we only need to update a portion of the data. Furthermore, unlike the Post and Put methods, the Patch method allows you to send only the entity that needs to be updated in the request body.
- DELETE: The Delete method, as its name implies, deletes the server's representations of resources via a specific URL. They also don't have a request body, just like the Get method.
- OPTIONS: In comparison to other methods, this one is not widely used. It returns information about the various methods and operations that the server supports at the given URL. It also includes an Allow header with a list of the HTTP methods that are permitted for the resource.
The Request URI
The Request URI, or Uniform Resource Identifier, aids in the identification of the resources to which the request refers. The format of a request URI is shown below.
The sender can specify the message's format as well as its ability to understand subsequent communications using the HTTP Protocol version. Furthermore, HTTP/1.1 is the widely used standardized protocol version.