Whenever we enter a URL in the browser, there is an HTTP request which is sent to the webserver, which then sends HTML content in response of the request. In simple words, HTTPS uses URL (Uniform Resource Identifier) for the purpose of identification of resources and for making a connect. Below are some of the features of HTTP:-
- There is no connection in HTTP.
- HTTP does not depend on the media which eases the transfer of all types of data.
- Server and client cannot keep any records whatsoever of the previous requests. This makes HTTP stateless.
A standard format -RFC822 is used for the transfer of data.
Here are some essential components of this general message that we must know before we proceed.
- Start line
- Either Zero or more headers.
- There is an empty line that indicates towards the header field’s end.
- Message Body, which is optional
It is the HTTP header where metadata and information regarding the HTTP method is stored whereas the data to be sent to the server is stored in the body.
It is quite simple to check the HTTPS requests. For Chrome browser, Select F12(Windows) and Command + Option + I for Mac OS. This path leads to Developer tools. Click on the tab labelled ‘Network’ to see the HTTP requests and received responses. We can also check the headers here. These HTTP requests are sent by using many HTTP methods.
Let us understand the HTTP methods in brief.
HTTP Methods
- GET: It is used generally to read (sometimes retrieve) a representation of a resource. If this method is successful without an error, it returns a representation in JSON along with a response status code 200. In case of an error, usually, it returns 404 (NOT FOUND) or 400 (BAD Request).
- POST: The most common use of this method is for creation of new resources, mainly subordinate resources which are subordinate for other parent resources. When a new resource is created, POST is responsible for mapping the new resource to the parent resource and also for assigning a new URI. Once this is completed without an error, it returns HTTP response code 201.
- PATCH: This method is mainly used for modification of resources. This request must only have the changes to be made to the resource and does not need the entire resource. The body needs to have clear instructions for making modifications to a resource that resides on the server. Referring to the above chart, PATCH is not a safe resource and there may be instances of collision with different PATCH requests which can corrupt the resources as they could be in different formats.
- DELETE: This request is used for deleting a resource which is identified by an ID or filters. When this request is completed successful, it returns response status code 204. When a resource is deleted and yet, DELETE request is sent multiple times, it may return the response code 404 (NOT FOUND) because the resource was already deleted and could not be found.
- PUT: This method is used for replacing or updating data which is either present on the server with the data passed on in the message body.
The most common HTTP methods include POST, GET, PUT, PATCH and DELETE have been discussed above. These are the HTTP methods which also relate to the CRUD Operations namely (Create, Read, Update and Delete). Many of the other HTTP methods are not used commonly.
While we are talking about HTTP methods, we must also include CRUD Operations in the discussion.
CRUD Operations
CRUD is an abbreviation that stands for Create, Retrieve,Update, and Delete. The term CRUD Operations is used for describing the process of implementation of basic operations of a database. It is important to understand how the process of implementing CRUD functions, for instance, creating a new table or changing an existing table in the database.
Importance of CRUD Operations
CRUD Operations are also referred to as the building blocks for any database. The functionality of the application totally depends on the data stored in the records. It is almost impossible to imagine any database to function without the CRUD Operations. One or some of the CRUD operations can be executed on multiple tables in a database and in some situations, it may be required to execute different operations on the same table.
Here is a brief explanation of the each of the CRUD operations.
- Create- It is used to add new rows to the database.
- Retrieve- It is used to get one particular row from the database.
- Update- It is used for making changes to the value of one particular column in a row that already exists.
- Delete- This operation is used for deleting records from the table.
Did you notice that some of these CRUD operations actually do match up to the HTTP methods? Some of the HTTP methods which perform the same function as HTTP method are –
HTTP Methods
Matching CRUD Operations
Retrieve
POST
GET
Update
PUT
Update
PATCH
Update
Difference between PUT and PATCH request
Based on the above mapping, interestingly many people think that PUT and PATCH requests have the same function. However, this is not true. While the PUT and PATCH request perform the same task of updating a resource at a given location, the methodology for both these requests is different.
PUT method updates the complete resource as per the data sent by the client, whereas, PATCH method executes partial updates to a resource.
The table below mentions a few more points of difference between PUT and PATCH request.
PUT
PATCH
Resource is modified completely
Resource is modified partially
It is believed to be idempotent. If one request is sent multiple times, it is still equal to one modification request.
HTTP Patch is non-idempotent. If one request is sent X times, it creates X resources along with X different URI s on the server.
Has higher bandwidth
Has a lower bandwidth as limited resources need modification.
The modified version is the enclosed entity which is saved on the original server and this stored version needs replacement as per the client’s request.
In the enclosed entity, there are steps or instructions for making modifications to the resource on the server and produce a new version.
Broadly, the web services are of two types-
- SOAP web services
- REST web services.