top of page

Rest API for dummies explained using mommies

REST API is an application programming interface which can be used by multiple clients to communicate with a server. Rest API is a kind of web-service which stores and retrieves necessary data. It provides great flexibility to developers since it does not need any dependent code libraries to access the web-services. Amongst the many protocols supported by REST, the most common one is HTTP. When a request is sent from the client using a HTTPRequest, a corresponding response is sent from the server using HTTPResponse. The most widely used machine readable format supported for requests and responses are JSON (Javascript Object Notification) and XML (Extensible Markup Language)

REST APIs can be used to perform different actions. Based on the actions, the relevant method should be used. The following are the 5 methods supported by REST.

  1. GET - This method is used to retrieve a data from database / server.

  2. POST - This method is used to create a new record.

  3. PUT - This method is used to modify / replace the record. It replaces the entire record.

  4. PATCH - This method is used to modify / update the record. It replaces parts of the record.

  5. DELETE - This method is used to delete the record.

Rest API

Let us see this with an example. We know that mothers never get enough rest. But lets take these rest-less mommies as an example and see how they use Rest API. :)

Amongst the plethora of demands by a newborn, diapering cements its place in the leaderboard.

A mother wants everything best for the baby. So, its obvious that the mother would want to choose the best diaper for her baby. So, she goes to a shopping website(assume: amazon) and searches for diapers. This will send a HTTP Request to amazon’s server to GET the list of all diapers. Amazon’s server responds with a HTTP Response which will be a JSON object(assume) containing a list of diapers with some basic details. Amazon’s website reads this Response and converts to human readable format and displays it on the webpage for the customer aka. mother to see it.

After performing several GETs, ie, browsing through several diapers, she chooses a particular diaper for her newborn baby and adds it to her list. This creates a POST request where a new record is created in amazon’s database containing the diaper brand, size, quantity, price etc.

Her baby keeps growing and soon outgrows the newborn size. Suppose, the mother still likes the diaper and just wants to size up, all she has to do is just choose the new diaper size. When she updates the diaper size from size newborn to size 1, this triggers a PATCH method where everything else remains same and only the size of the diaper is changed.

It is very common for the mother to not be delighted with the current brand and decide to switch to an alternate the brand. Here, the mother will initiate a PUT request where the entire data containing previously chosen brand is modified and replaced with data corresponding to the newly chosen brand.

Finally, after a series of experiments involving several GETs, POSTs, PUTs and PATCHs, it's time for the mother to potty train the child. If she succeeds in training the child(Hurray!!) , then the diapers will no longer be required. This triggers a DELETE request.

13,400 views12 comments
bottom of page