All Articles

REST CRUD explained (analogy)

C: POST routes

The HTTP POST method sends data to the server. The type of the body of the request is indicated by the Content-Type header.

HTTP POST routes can be thought of as a mail carrier delivering a letter. Just as you would write a letter with information and send it to a recipient through a mail carrier. with a POST route you can send data/information to a server.

Imagine you need to send a package to a friend. You package all items to send, address it to your friend, and give it to a mail carrier. The mail carrier acts like the POST route, delivering the package to your friend.

Similarly a POST route, you can send data to a server. Like form data, file uploads, JSON payloads, etc. After it is received by the server it will start processing the data. Just like the mail carrier delivering the package, the POST route delivers the data to the server.

R: GET routes

The HTTP GET method requests a representation of the specified resource. Requests using GET should only be used to request data (they shouldn’t include data).

HTTP GET routes can be thought of as an address/map to a location. Just like using an address to find a specific house or building. A GET route allows you to access specific resources or information stored on a server.

Imagine a library where you want to find a specific book. The librarian would give you the number for that book which acts like the GET route. By using this number, you would be able to locate the book on the shelves and get the information you need.

Similarly a GET route provides the address/path to the specific resource you are looking for on the server. Such as a web page, image, or piece of data. Just like the librarian, the server returns the requested resource to you.

U: PUT routes

The difference between PUT and POST is that PUT is idempotent: calling it once or several times successively has the same effect (that is no side effect), where successive identical POST may have additional effects, like passing an order several times.

HTTP PUT routes can be thought of as updating or replacing a piece of information. Just as you would modify or replace a document on your computer. With a PUT route you can update/replace existing data on a server.

Imagine you have a recipe book. You want to update/replace a recipe. You would open the recipe book, locate the recipe you want to modify, make the changes, then write the changes back to the book. The act of saving the updated recipe back to the book is similar to making a PUT request to a server.

With a PUT route, you can update/replace a resource on the server by sending a request with the updated data. The server then replaces the existing data with new data (updating it). Just as you modified the recipe in the recipe book. A PUT route allows you to modify a resource on a server.

D: DELETE routes

The HTTP DELETE request method deletes the specified resource.

HTTP DELETE routes can be thought of as removing or deleting a piece of information. just like deleting a file on your computer. A DELETE route you will remove resources from a server.

Imagine you have a collection of CDs. You want to remove one that you no longer listen to. You would find the CD you want to delete, remove it from its case, and discard it. The act of discarding the CD is similar to making a DELETE request.

With a DELETE route, you can remove a resource sending a request with the resource you want deleted. The server then deletes the specified resource, removing it from the server. Just as you discarded a CD from your collection, a DELETE route allows you to remove a resource from a server.

Published Feb 9, 2023

L3 software engineer