DEV Community

Discussion on: Explain Middleware Like I'm Five

Collapse
 
alchermd profile image
John Alcher • Edited

Daniel is an expert fruit juicer. Fruit is being sent to him and he makes delicious juice out of them.

One day, he was sent a container full of apples. As he was about to start his work, he noticed that some had bad spots. Bummer, he thought, as he threw these bad apples away. Another shipment of oranges come in. He's surprised to see that some were too small for his liking. Annoyed, he threw them away as well. Then the last package came in, a bag of fresh mangoes. It turns out a handful were unripe! Feeling outraged, he threw those as well and continued his work.

Weeks went on Daniel had enough. Filtering through these fruits are taking too much time. To be fair, juicing is his skill, not filtering fruits. He decided to hire John, Jane, and Jonah. John checks the incoming shipment for bad spots, and hands off the good ones to Jane. Jane checks the sizes of the fruits and gives the one that have the right size to Jonah. Jonah, lastly, checks if the fruits are ripe for juicing. Alas, Daniel receives the fruits that are prime and ready for juicing!


Daniel = Server
Fruits = HTTP Request
John, Jane, Jonah = Middlewares


PS. Idk anything about juicing so this might be a silly example lmao.

Collapse
 
wallwrecker profile image
wallWrecker • Edited

so a it's a function that checks if the fruits where good for juice extraction.

Collapse
 
danny2590 profile image
Daniel Encarnacion

This was wonderfully insightful! Thank you very much :)

Collapse
 
thebuildguy profile image
Tulsi Prasad

This is the best real life example of any tech thing I've ever read! ❤