What is CRUD?
CRUD is a "cool" term used to abbreviate how web apps work.
CRUD stands for Create, Read, Update and Delete. Web apps are created to do these four operations. Using Twitter, I will explain how these operations work.
Prerequisites
Understanding how the Internet works
Requests and responses
Create
Create is the operation used to refer to POST
requests. A POST
request is used to send data to the server. According to the MDN,
The
POST
method submits an entity to the specified resource, often causing a change in state or side effects on the server.
For example,
When you create a new tweet, a POST
request is sent to the server. The tweet is saved in the database and added to the timeline.
A POST
request can also be initiated when a new Twitter account is created.
Read
Read is the operation used to refer to GET
requests. A GET
request is used to retrieve data from the server. According to the MDN,
The
GET
method requests a representation of the specified resource. Requests usingGET
should only retrieve data.
For example,
When you view a tweet, a GET
request is sent to the server and the tweet is sent as a response.
Update
Update is the operation used to refer to PUT
requests. A PUT
request is used to add data that is tied to an existing resource in the database. According to the MDN,
The HTTP
PUT
request method creates a new resource or replaces a representation of the target resource with the request payload.
For example,
When you like or retweet a tweet, a PUT
request is sent. The server adds the number of likes or retweets in the server and sends back a response
Delete
Delete is the operation used to refer to DELETE
requests. A DELETE
request is used to delete data from the server. According to the MDN,
The HTTP
DELETE
request method deletes the specified resource.
For example,
When you delete a tweet, a DELETE
request is sent to the server. The tweet is deleted and the response is sent back. Then, the tweet is removed from your profile.
In the video above, the retweet is undone by sending a DELETE
request. The number of retweets is reduced and updated as a response to the request.
Summary
CRUD stands for Create, Read, Update and Delete.
Create is the operation used to refer to
POST
requests.A
POST
request is used to send data to the server.Read is the operation used to refer to
GET
requests.A
GET
request is used to retrieve data from the server.Update is the operation used to refer to
PUT
requests.A
PUT
request is used to add data that is tied to an existing resource in the database.Delete is the operation used to refer to
DELETE
requests.A
DELETE
request is used to delete data from the server.