1

Explain Middleware like I'm five

 3 years ago
source link: https://dev.to/peter/explain-middleware-like-i-m-five-4ekn
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
Cover image for Explain Middleware like I'm five

Explain Middleware like I'm five

May 20

・1 min read

Discussion (10)

pic

CollapseExpand

It's the stuff between the leftware and the rightware.

Actually, it's a pretty vague and broad definition.

Middleware is kind of like a translator or a mediator; it helps two or more "things" communicate with each other.

Sometimes we call it "glue code" because it usually connects two software projects that need to work together.

Some examples might include: a database and a web application, a network and a server, or an operating system and an application.

My analogy for a five year old: When you brush your teeth, your toothbrush is the middleware between the toothpaste and your teeth. We could just pour toothpaste in your mouth and call it done, but using a toothbrush is easier and very helpful.

Comment button Reply

CollapseExpand

Imagine you're looking to cook a meal. You get the ingredients and then you have to prepare them and then apply a recipe. Middleware is like the preparation stage. You can do it all by hand, or you can stick some of the ingredients in a machine which can do some of it for you, and you can combine different tech in different ways to get it ready for the main thing you're looking to do, but the main cooking happens once you have gotten the ingredients ready and prepared. The main cooking is analogous to how you might handle a network request on a REST endpoint once it reaches a controller method, but he middleware is how you can process that request before it gets there. This might be to apply some validation logic and reject the request if it doesn't meet it, apply authentication and authorisation, perform logging, process aspects of the request, etc. Hopefully that's of some help. :-)

Comment button Reply

CollapseExpand

Speaking of Rails middleware like Rack or enterprise middleware like MQ?

Comment button Reply

CollapseExpand

or even redux middleware in react... so many uses of that term, all similar in some sense, but probably different enough if you are specifically trying to understand that technology...

Comment button Reply

CollapseExpand

In general it is more like a piece of code that will run between two task. For example, if you want to check the authentication everytime someone wants to access a webpapge before sending the page, you would have a middleware that would handle this auth checking everytime. This way, you only have one auth system that handles every connections you want. And you can remove this need of auth just by removing this middleware for a specific page par example.

Don't know if it is clear or 100% accurate so don't be shy and correct me 😁

Comment button Reply

CollapseExpand

You've been playing with your toys and they're scattered all over the room. Mummy tells you to put them all away in their toyboxes, but there's loads of them, so you ask daddy to help you. You pick up each toy and give it to daddy who collects them up, checks that they're still working, figures out which box they go in and puts them away. Daddy is your middleware.

Comment button Reply

CollapseExpand

Making sandwiches, likely multi-layered.
Oreos with multiple filings

Comment button Reply

CollapseExpandCollapseExpandCollapseExpand

Middleware is using a pancake fryer instead of a griddle.

Comment button Reply


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK