DEV Community

Cover image for REST API Explanation for 6 years old
Shubh Sharma
Shubh Sharma

Posted on

REST API Explanation for 6 years old

Intro

Imagine you have a vending machine. 💭🤖

When you approach the vending machine and press the buttons, it performs certain actions and gives you the desired item.

Now, think of the vending machine as a SERVER (a computer which serves or gives) and you as a CLIENT (a computer which need something) wants to interact with it.

REST API

A REST API is like a set of rules that the vending machine and you follow to communicate with each other.

It defines how you can ask the SERVER for specific items and how the SERVER responds to your requests. 🟢

In this case, the vending machine has different buttons (ENDPOINTS) representing different items (RESOURCES) you can get.

For example, button 1 for snacks, button 2 for drinks, and 3 for candies 🍭.

Each button has a unique label (URL) that tells the vending machine what you want.

To get the item you want, you press the button (send an HTTP request) to the vending machine.

The machine understands the request (GET, POST, PUT, DELETE, etc) and performs the necessary action according to your request, It may give you the item you requested (RESPONSE) or perform some other action based on your request, or sometimes might show you an error if item is not available.

Stateless Behavior

The vending machine is "stateless", meaning it doesn't remember anything about your previous requests.

Each time you press a button, you provide all the necessary information for the machine to understand what you want.

This is because HTTP is a stateless protocol.

Conclusion

Similar to a vending machine, in a REST API, the server and client (which could be a website or mobile app) interacts using some rules.

The client (You) send requests to the server's specific URLs (ENDPOINTS) to get or manipulate data.

The server (Vending machine) understands the requests and responds accordingly.

REST APIs are widely used in web development to create services that allow different systems and applications to communicate and exchange data.

Top comments (2)

Collapse
 
forbalazs profile image
forbalazs

Great explanation, thanks for sharing!

Collapse
 
shubhsharma19 profile image
Shubh Sharma

Thankyou for reading :)