Perhaps, like many, I do not always manage to explain complicated things in simple language, I become verbose, pay excessive attention to details and involuntarily use professionalism. Perhaps that is why I drew attention to the article
How I Explained REST to My Wife , in which
Ryan Tomayko so easily tells his wife about REST and the principles of HTTP operation. In the headlines of the article there was a list of languages ​​in which this article and this list of 6 languages ​​were translated, firstly, made it clear that I was not alone, and secondly, showed that the article was worth adding a translation in Russian.
PS This is my first translation, but you can safely criticize, it will be useful for me.
As I explained to my wife what REST is
Wife: Who is
Roy Fielding ?
')
Ryan: One smart guy.
Wife: Yes? And what did he do?
Ryan: He helped write the first web server and then did
a lot of work to explain why the web works the way it works.
Its name is on the protocol
specification , which is used by your browser to get pages from the server.
Wife: And how does it work?
Ryan: Web?
Wife: Yes
Ryan: Hm. Well, actually, this is all pretty amazing. And the funny thing is that this is all very undervalued. The protocol I'm talking about, HTTP, is capable of various wonderful things that people ignore for some reason.
Wife: You mean that “http” which I write at the beginning of any address in the browser?
Ryan: Exactly. This part of the address tells the browser which protocol to use. What you write is one of the most important breakthroughs in the history of information technology.
Wife: Why?
Ryan: Because he is able to describe the position of anything anywhere in the world, from anywhere in the world. This is the basis of the Web. You can think of this as GPS coordinates for knowledge and information.
Wife: For web pages?
Ryan: Actually, for anything. This guy, Roy Fielding, in his research says a lot about what can be addressed using HTTP. The web is built on an architectural style called
REST . REST gives the definition of a resource, which in turn is the object of addressing.
Wife: Internet page is a resource?
Ryan: Like that. The webpage is a representation of the resource. A resource in itself is only a general concept. The URL is what you drive into the browser ...
Wife: I know what a URL is ...
Ryan: Good. URLs inform the browser that there is a resource somewhere. The browser can request a specific view of this resource. More specifically, the browser requests a webpage which is a representation of this resource.
Wife: And what other types of representations exist?
Ryan: Actually, performances are not very popular. In most cases, the resource has only one view. But we hope that in future they will be used more, as new formats appear all the time.
Wife: For example?
Ryan: For example, there is such a resource that people call web services (web services). They mean a lot of different things for different people, but at the core lies the idea that machines can use the Internet just as people use it.
Wife: Any regular robots?
Ryan: Not really. I do not mean that the machines will sit at the table and browse the Internet. Computers can use the same protocols to send messages to each other. We have been doing this for a long time, but at the moment there are no technologies, using which you could communicate with all the machines around the world.
Wife: Why?
Ryan: Because they were not designed for this. When Fielding and his colleagues began working on the Web, the ability to communicate with any machine, anywhere in the world, was the main goal. Most of the technologies that we now use to work in order to force computers to exchange information do not have such requirements. We only need to interact with a small group of machines.
Wife: And now there is a need to communicate with all of them?
Ryan: Yes, and more. We need the ability to communicate with all machines about all things present on all other machines. That is, we need a way to force one machine to inform another machine about a resource that may be on a third machine.
Wife: What?
Ryan: Let's pretend you are talking to your sister, and she wants to take a brush or something from you. But you don’t have her, she’s with mom, so you tell your sister that she’s better to turn to mom. It happens all the time in the real world and it also happens all the time when the machines start to communicate.
Wife: And how do cars tell each other where the things they need are?
Ryan: Using the URL, of course. If everything that the machines talk about has a corresponding URL, then you have
created a machine equivalent to a noun . The fact that you, me and the rest of the world have agreed to designate certain things from the real world as nouns is quite important, right?
Wife: Yes
Ryan: Machines do not have a universal noun and this is the cause of their problems. Each programming language, database, or other type of system has its own way of talking about nouns. That is why the URL is so important. It allows all systems to inform each other about their nouns.
Wife: But when I look at the webpage, I don’t think about it that way.
Ryan: And no one thinks. Except for Fielding and a few more people.
Wife: What about verbs, pronouns and adjectives?
Ryan: Funny you asked because this is another big part of REST. Well, at least the verbs.
Wife: I was just joking.
Ryan: It was funny, but it wasn't a joke. Verbs are important and they are an important principle in programming and polymorphism. Polymorphism is only an abstruse way to say that different nouns can have common verbs applicable to them.
Wife: I did not understand
Ryan: Look. Look at the coffee table. What are nouns? Cup, tray, newspaper, remote. Now let's define the actions that can be done with all these things.
Wife: I still do not understand
Ryan: You can take them, right? You can raise them. You can break them. You can burn them. You can apply all these verbs to the things there.
Wife: Yes?
Ryan: This is important. What if, instead of telling you to “take the cup,” “take the newspaper,” “take the remote,” what if I should use different verbs with each noun? I could not use the word “take” so universally, but I would have to select a new word for each verb / noun combination
Wife: Wow! This is strange
Ryan: Yes it is. Our brain is smart enough to understand that the same verbs can be applied to different nouns. Some verbs are more specific and apply only to a narrow circle of nouns. For example, I can not drive a mug, I can not drink a car. But some of them are almost universal, for example, take (GET), put (PUT) and delete (DELETE).
Wife: You cannot delete (DELETE) a cup.
Ryan: Yes, but you can throw her out. Was it another joke?
Wife: Yes
Ryan: Anyway, HTTP is a protocol that Fielding and colleagues created entirely about how to apply verbs to nouns. For example, when you want to open a webpage, the browser applies an HTTP GET (take) to the entered URL and as a result gets this page. Web pages usually have pictures, right? They are separate resources. The webpage only indicates the URL of these images, and the browser applies more HTTP GET requests to them until all resources are received and the page is displayed. But it is important here that there are single types of interaction with the most different types of nouns. Whether the noun is a picture, text, video, sound, presentation is not important. I can get (GET) all this with a URL.
Wife: Looks like to get (GET) a rather important verb.
Ryan: It is. Especially when you use the browser, because the browser for the most part deals with getting (GET). It does not use most of the other types of interaction with resources and this is a problem because it convinced a large number of people that HTTP only exists for receiving (GET). But HTTP is
a general purpose protocol for applying verbs to nouns .
Wife: Great. But I still do not see how this changes anything. What verbs and nouns do you need?
Ryan: Well, in general, nouns already exist, but they are not in that format.
Imagine wandering around www.amazon.com looking for a Christmas present for me. Imagine that each item is a noun. If they had a clear understanding of the machines, you could do a lot of interesting things with these products.
Wife: Why the machine can not understand the usual web page?
Ryan: Because web pages are designed for people. The car doesn’t care about the layout and style. Machines just need data. Ideally, each URL should have a representation for the person and a representation for the machine. When a machine requests (GET) a resource, it will request a machine resource. And when it makes the browser - understandable to humans.
Wife: And people will have to do machine views for all their pages?
Ryan: If it's worth it.
Look, we talk about this with a large amount of abstraction. Let's take a real example. You are a teacher and you can bet you have a large computer system at school, or at least three or four computers that allow you to manage students: what lessons they are in, what class they study, emergency contact information, information about textbooks and stuff. If this system is a web application, then, most likely, there is a URL for each noun listed: student, teacher, class, textbook, and so on. At the moment, by entering the URL into the browser, you will get a webpage. If for each URL there was a view that was understandable for the machine, then it would be enough just to add a new tool to the system, since all this information would be used in standard ways. It would also make communication between such systems a bit easier. Or we could build a regional or even federal system that could communicate with the systems of individual schools in order to collect test results. The possibilities are endless.
Each of the systems would receive information from other systems using simple HTTP GET (receive). If one system needs to add something to another system, it would be using HTTP POST (send). If the system needed to update something on another system, it would use HTTP PUT (place). The only thing left to articulate is how the data should look.
Wife: And this is what you, computer scientists, are working on now? Deciding what the data should look like?
Ryan: Unfortunately not. Instead, most are busy writing heaps of complex specifications to accomplish these goals in other ways that are not so convenient or eloquent. Nouns are not universal and verbs are not polymorphic. We spend a lot of time to approve and start using something that is very similar to another system that has already failed. We use HTTP, but only because this protocol allows us to interact less with our network and security specialists. We replace simplicity with bright things and customization wizards.
Wife: But why?
Ryan: I don't know.
Wife: Why won't you do something?
Ryan: Maybe in the future.
(
Translator's note: after the comments of
xanep and
Ano corrected the author's name from Ryan to Ryan)