REST API (HTTP) vs Websockets - Concept Overview With Example

  Рет қаралды 255,591

Be A Better Dev

Be A Better Dev

Күн бұрын

Learn the differnce between a REST API and Websockets in this practical example.
In this video, we use a realtime chatting application as a toy example to understand the difference between REST APIs and Websockets. We examine the problem through the lens of both technologies and show how the approach will be different using one over the other.
Become a Better Developer Using the Courses I Recommend Below:
- Master FAANG Coding Interviews - bit.ly/3CVgRN9
- Learn AWS From Scratch - bit.ly/3gasoAm
- Master Python here - bit.ly/3yJFJpI
🎉SUPPORT BE A BETTER DEV🎉
Become a Patron: / beabetterdev
📚 MY RECOMMENDED READING LIST FOR SOFTWARE DEVELOPERS📚
Clean Code - amzn.to/37T7xdP
Clean Architecture - amzn.to/3sCEGCe
Head First Design Patterns - amzn.to/37WXAMy
Domain Driven Design - amzn.to/3aWSW2W
Code Complete - amzn.to/3ksQDrB
The Pragmatic Programmer - amzn.to/3uH4kaQ
Algorithms - amzn.to/3syvyP5
Working Effectively with Legacy Code - amzn.to/3kvMza7
Refactoring - amzn.to/3r6FQ8U
🎙 MY RECORDING EQUIPMENT 🎙
Shure SM58 Microphone - amzn.to/3r5Hrf9
Behringer UM2 Audio Interface - amzn.to/2MuEllM
XLR Cable - amzn.to/3uGyZFx
Acoustic Sound Absorbing Foam Panels - amzn.to/3ktIrY6
Desk Microphone Mount - amzn.to/3qXMVIO
Logitech C920s Webcam - amzn.to/303zGu9
Fujilm XS10 Camera - amzn.to/3uGa30E
Fujifilm XF 35mm F2 Lens - amzn.to/3rentPe
Neewer 2 Piece Studio Lights - amzn.to/3uyoa8p
💻 MY DESKTOP EQUIPMENT 💻
Dell 34 inch Ultrawide Monitor - amzn.to/2NJwph6
Autonomous ErgoChair 2 - bit.ly/2YzomEm
Autonomous SmartDesk 2 Standing Desk - bit.ly/2YzomEm
MX Master 3 Productivity Mouse - amzn.to/3aYwKVZ
Das Keyboard Prime 13 MX Brown Mechanical- amzn.to/3uH6VBF
Veikk A15 Drawing Tablet - amzn.to/3uBRWsN
🌎 Find me here:
Twitter - / beabetterdevv
Instagram - / beabetterdevv
Patreon - Donations help fund additional content - / beabetterdev
#REST
#Websockets
#API

Пікірлер: 130
@BeABetterDev
@BeABetterDev 2 жыл бұрын
Looking to create a REST API or setup Websockets using AWS? Check out these step by step walkthrough videos below: REST API on API Gateway - kzbin.info/www/bejne/q3fWkpx7nddksNU Websockets on API Gateway - kzbin.info/www/bejne/fHrVq56qbNB7bpI
@jadeedstoresupport8916
@jadeedstoresupport8916 2 жыл бұрын
Lets hope someday majority of tech presenters on youtube would know how to a make a to-the-point great video - like this one. No bs, no mumbo jumbo, no need to market the channel or request for subscription etc.; just focusing on bringing the concepts home. Great job, man.
@cyberchef8344
@cyberchef8344 2 жыл бұрын
KZbinrs statistically get more subs and likes when they ask for them. You’re taking for granted how much effort goes into making videos. Why shouldn’t they try to maximize their income?
@fastorial
@fastorial 2 жыл бұрын
@@cyberchef8344 I too don't spend time asking for likes or subs on my channel. This is my mindset: "Make a video so good that when someone watches it, they feel like the urge to like it and then subscribe for more such content". If you don't make someone feel that, then maybe you have to improve yourself. But yes, this is just my opinion.
@cyberchef8344
@cyberchef8344 2 жыл бұрын
@@fastorial that’s definitely a good mindset to have, but at the end of the day it just boils down to trying to make the best quality videos you can. You should absolutely do that because that’s the main factor in growing an audience. With that being said, you can do that and still ask for a like or subscription. It’s not like that takes up much time. Plus, sometimes people watching videos just don’t even think about liking it. It’s not really a priority. Asking for likes has been shown statistically to produce more results. I’m not saying you have to do this, but it really is one of those situations where there is no reason not to.
@freshlix9554
@freshlix9554 2 жыл бұрын
The client still has to play *ping-pong* with the server to keep the connection alive, but it's safe to say, that a lot of overhead - especially the HTTP-Header - are cut out by websockets and it's my go to for web applications. In my view the REST model is still important, especially for static sites and APIs, which don't depend on near real time communication. Overall, you've done a pretty good video, it's a great explanation for newbies ^_^
@thedevmachine
@thedevmachine 2 жыл бұрын
HTTP/2 solves the header overhead.
@Zoditu
@Zoditu 2 жыл бұрын
This is a cool explaining video about the usage of each... In real life you usually use both in the same application. In my case, I had to build a REST service API with some endpoints, but there is a particular Endpoint that creates a user instance for remote execution, so N users in a project can start an engine in their PC and making a GET call to the endpoint 'url/tasks/SRS' will see how many remote execution nodes are available for the project, make a direct connection between the client and a user engine with websockets and start making a remote execution and see the stdout in real time... This is very useful when having a very heavy software that requires multiple instances to run modules or subprocesses of the main one :D!
@maid768
@maid768 2 жыл бұрын
Ok so why do you have the REST API then? I understand that one of your endpoints from service API is creating an instance (websocket technique). But what other calls do the users make for the remote execution? Greetings from germany
@SaiKumar-vf9lz
@SaiKumar-vf9lz 2 жыл бұрын
Crisp and straight to point 👍🏽
@MertOguz
@MertOguz 2 жыл бұрын
Recently I had to rewrite backend of my online game from REST API to a websocket. The problem is this game was my college project and something completely amateur. But I thought I could make things more efficent by fixing the backend. By switching to websocket from rest api, average ping dropped to 30 from 100, which seemed fine. But still I had the client side playing ping-pong thing with the server, which reduces the performance of the server extremely high with each player being online. After learning more about websockets, I realised that I have to change whole logic of my communication structcure. I just removed the old system completely and switched to the websocket, I hope I will be able to implement a new structcure that is efficent for the use of the websocket. Thanks for the video and all the information.
@Nothing-jo8ci
@Nothing-jo8ci 2 жыл бұрын
I'm building an online game too. But it's ludo's instead. So it's like chess, but with 4 people max. I'm thinking of using websockets too, because it's a real time app, and should be as fast as possible to present better player experience. I'm using django-postgresql. Maybe I should use node js instead, but I hate javascript.
@khaledqa6035
@khaledqa6035 2 жыл бұрын
Very clear and simple description. Thank you very much
@JonathanNelson-nelsonj3
@JonathanNelson-nelsonj3 2 жыл бұрын
It is good to note that the web sockets opens the connection across all the network components between the device and server. Components such as NAT will prevent the server from sending a message directly to the device without the web socket.
@farzadb
@farzadb 2 жыл бұрын
Clean and simple explanation, nice job!
@vasiliydorofeev1355
@vasiliydorofeev1355 2 жыл бұрын
so cool and easy. Please continue!
@pixelettee
@pixelettee 10 ай бұрын
Thank you. A very clear and to the point presentation.
@learnandexplorewithsab
@learnandexplorewithsab 2 жыл бұрын
Love your straight forward presentation man!
@BeABetterDev
@BeABetterDev 2 жыл бұрын
Thanks Saborni!
@vikranttyagiRN
@vikranttyagiRN 2 жыл бұрын
Awesome explanation. Thanks
@farazahmed1668
@farazahmed1668 2 жыл бұрын
Thank you so much for comming up with an excellent explaination of complex mechanisms.
@BeABetterDev
@BeABetterDev 2 жыл бұрын
You're very welcome Faraz!
@srb1855
@srb1855 2 жыл бұрын
Thank you for the excellent and concise presentation of these two techniques! 👍
@BeABetterDev
@BeABetterDev 2 жыл бұрын
You're very welcome!
@AlexBoltonKing
@AlexBoltonKing 2 жыл бұрын
Good video explaining the differences and going into detail with long vs short polling. However, for this setup I would say even sockets is a bit of an outdated way of doing things. WebRTC would be the prefered method where messages are peer to peer which would only require a server for the initial peer to peer connection setup and then all messages bypass the server. Obviously depends on use case - do you need to store messages in a DB for later etc. but for a simple chat system that doesn't need stored history I would say webRTC would be the way to do this.
@doctorpanga290
@doctorpanga290 2 жыл бұрын
Man I love your videos. Please do a vid on automation using AWS if you ever find the time
@gui_dev_
@gui_dev_ Жыл бұрын
Awesome. Your way to learn it's very clear! Thanks to share this content.
@BeABetterDev
@BeABetterDev Жыл бұрын
Glad it was helpful!
@webmaster246
@webmaster246 2 жыл бұрын
That was smooth!!!
@christianibiri
@christianibiri 2 жыл бұрын
Super clear! thank you
@BeABetterDev
@BeABetterDev 2 жыл бұрын
You're very welcome Christian!
@benellis-moat6247
@benellis-moat6247 3 ай бұрын
very good clear and concise video
@stephaneiung3030
@stephaneiung3030 2 жыл бұрын
Very clear explanation , thanks for posting it !
@BeABetterDev
@BeABetterDev 2 жыл бұрын
Glad it was helpful!
@shantanu83
@shantanu83 11 ай бұрын
Brilliantly explained! Need more such top level videos to deconstruct software.
@BeABetterDev
@BeABetterDev 11 ай бұрын
Thanks!
@rickharold7884
@rickharold7884 2 жыл бұрын
Nice summary
@nathanwilcox8395
@nathanwilcox8395 2 жыл бұрын
not saying this comment applies to this video, but miss the dislike metric. it gives a clear indication of how useful a technical video is going to be
@ghilmanfatih9751
@ghilmanfatih9751 2 жыл бұрын
Smooth explanation
@nathanbenton2051
@nathanbenton2051 2 жыл бұрын
awesome stuff thanks
@saadowain3511
@saadowain3511 2 жыл бұрын
Amazing explanation
@BeABetterDev
@BeABetterDev 2 жыл бұрын
Glad it was helpful!
@ShubhodeepDeveloper
@ShubhodeepDeveloper 9 ай бұрын
Amazing explanation..💯
@AeroPR
@AeroPR 2 жыл бұрын
Excellent video. 🙏 Thanks
@BeABetterDev
@BeABetterDev 2 жыл бұрын
You're very welcome!
@user-gu5ts5nx8r
@user-gu5ts5nx8r 2 жыл бұрын
very helpful, thank you.
@BeABetterDev
@BeABetterDev 2 жыл бұрын
You're very welcome!
@bjarneschmitz5160
@bjarneschmitz5160 2 жыл бұрын
Amazing!
@jasper5016
@jasper5016 2 жыл бұрын
This is a really good explanation in 7 mins. Thanks.
@laofeng_panda
@laofeng_panda 2 жыл бұрын
Great content!
@BeABetterDev
@BeABetterDev 2 жыл бұрын
Thank you!
@ismailcotton913
@ismailcotton913 2 жыл бұрын
Thank you for the explanation.
@BeABetterDev
@BeABetterDev 2 жыл бұрын
You're very welcome!
@ayushgupta8239
@ayushgupta8239 2 жыл бұрын
Thank you so much!!!
@BeABetterDev
@BeABetterDev 2 жыл бұрын
You're very welcome!
@computerprogrammingwebtech3017
@computerprogrammingwebtech3017 2 жыл бұрын
This a clear and simple explanation of the difference between REST API and Websockets! Well done.
@vansterhook
@vansterhook 9 ай бұрын
This example should be on the Wikipedia page on WebSockets. Well done!
@BeABetterDev
@BeABetterDev 9 ай бұрын
Thank you so much!
@theonly1me
@theonly1me 2 жыл бұрын
Subbed!
@hfernandez13
@hfernandez13 2 жыл бұрын
thanks this video was really helpful
@BeABetterDev
@BeABetterDev 2 жыл бұрын
You're very welcome!
@RandomShowerThoughts
@RandomShowerThoughts 2 жыл бұрын
Beautiful explanation
@BeABetterDev
@BeABetterDev 2 жыл бұрын
Thank you!
@dragulaxis
@dragulaxis 2 жыл бұрын
thank you
@drakkorvladimir4012
@drakkorvladimir4012 2 жыл бұрын
I use dyndns and want to use websockets on a small esp32 at home. I can connect from anywhere remote but not with websockets. Any help would be so appreciated.
@siddharathadhumale3683
@siddharathadhumale3683 2 жыл бұрын
Thanks for this video
@BeABetterDev
@BeABetterDev 2 жыл бұрын
You're very welcome!
@francksgenlecroyant
@francksgenlecroyant 2 жыл бұрын
Perfect
@werner6816
@werner6816 Жыл бұрын
excellent
@md.mohiulislam6516
@md.mohiulislam6516 Жыл бұрын
tnx a loooooot❤️
@bubuli
@bubuli 2 жыл бұрын
this is good but you should have touched upon a little bit with the new bi-directional aspect of HTTP/2 and also on SSE.
@techandtravelbyakash9858
@techandtravelbyakash9858 2 жыл бұрын
Can you please put a video on redshift and elasticcache
@kfelix2934
@kfelix2934 2 жыл бұрын
IIRC slack & whatsapp messaging both uses websockets which is why is quick.
@BeABetterDev
@BeABetterDev 2 жыл бұрын
Correct!
@CharlesOkwuagwu
@CharlesOkwuagwu 2 жыл бұрын
Server-Sent-Events(SSE) does the same without WebSockets
@priyankaojha1
@priyankaojha1 Жыл бұрын
What is the protocol / approach used to upload say videos on KZbin or maybe Netflix etc. Like 5 to 10 gb. Thanks
@EdFrench_uk
@EdFrench_uk 2 жыл бұрын
Last time I looked at this, most websockets communication with end users had to use long polling under the hood. Did this change ye
@AkashKeserwani
@AkashKeserwani 2 жыл бұрын
Are John and Mary winchesters? jokes aside nice and informative video.
@mr_green8556
@mr_green8556 2 жыл бұрын
What would be that scaling concerns qith websockets?
@xxx.xxx.xxx.xx1joker706
@xxx.xxx.xxx.xx1joker706 2 жыл бұрын
What's up with pricing? WebSockets stay opened during chat. This is better, but I have heard that you must close the services connected to WebSockets?
@tiagomaia5269
@tiagomaia5269 2 жыл бұрын
I like the example , i just don't understand why in the Rest case would you be waiting for the delay to update the messages when you could use the Publisher/Subscriber or the Observer pattern and then you would be updated everytime a new message is sent automatically , this way you would not waste resources making get requests all the time and you would not have the delay of the messages
@eugenekostyukevich4917
@eugenekostyukevich4917 2 жыл бұрын
Totally agree! I was looking for this comment! Additionally, I don’t see any problems with initiating new instance of the chat on receiving side (Mary in example), server should just create it for her and push messages to it. Also, this patterns are great way to handle group chats!
@yicai7
@yicai7 Жыл бұрын
Awesome
@BeABetterDev
@BeABetterDev Жыл бұрын
Thanks!
@chienle1492
@chienle1492 2 жыл бұрын
Can you do a video on how to scale websocket?
@glowiever
@glowiever 2 жыл бұрын
it's not scalable by default. maybe try to mimics mmorpg architecture, using redundant nodes perhaps.
@stephenJpollei
@stephenJpollei 2 жыл бұрын
Seems like it doesn't have to be REST vs. websocket. They had chat based on cgi in the 2000s that was very similar to your long-poll rest example, except you don't keep calling it, just have structured messages that you output as required.
@andythebritton
@andythebritton 2 жыл бұрын
This might be better described as "HTTP vs Websockets".
@saifmohamed1776
@saifmohamed1776 2 жыл бұрын
Could you please recommend for me a book that's touch kinda of the important concepts necessary for backend engineer , or something like that Thank you your videos are awesome
@BipinOli90
@BipinOli90 2 жыл бұрын
Did you get the idea for this video from the comment in your previous video about stock tracker?
@BeABetterDev
@BeABetterDev 2 жыл бұрын
Yes I did!
@Anorch-oy9jk
@Anorch-oy9jk 3 ай бұрын
is there a way to use websockets and rest endpoints? I have 2 clients who connect via websockets and 2 who are making api calls. I cant use socketio because of the handshake with the websocket clients. My clients expect a server hosted on ws://IP:port. My Socketio server uses http and later after deployment https. Which is fine for the api clients as i can define endpoints with flask socketio. But the websocket clients cannot connect. And I cannot host 2 servers either after deployment. Any options I have in python?
@_yeatts
@_yeatts 2 жыл бұрын
Great video! But does anyone else notice that the Mary and John boxes are not the same distance from the chat app box? lol my ocd is kicking in 😬
@BeABetterDev
@BeABetterDev 2 жыл бұрын
Yikes I try to align them but I guess I missed them!
@chandansh9692
@chandansh9692 2 жыл бұрын
Can someone please provide information on how to incorporate websockets in MVC architecture. Specifically how do I use websockets in controllers?
@xinfatang7352
@xinfatang7352 2 жыл бұрын
When you want to implemention offline messages on websockets, you will start miss the REST or HTTP things, such as cache, compress etc. Websockets is a low level transfer layer on the web, i don't think it is comparable with REST, we need a standard application protocol up on websockets, otherwise we should build it by ourself.
@knowiz8071
@knowiz8071 2 жыл бұрын
SignalR from Microsoft will solve that.
@ediec
@ediec 2 жыл бұрын
Why don't just use GraphQL Subscription in this case?
@songkai1981
@songkai1981 2 жыл бұрын
Websocket is http 2.0 native feature. REST API is http-based messaging architecture. Right?
@JavierMonsuarez
@JavierMonsuarez 2 жыл бұрын
WebSockets are so underrated.
@maxyan2572
@maxyan2572 Жыл бұрын
how about using a lighter-weight tool that lets the server signal clients to do the restful api update instead of using socket to pass the actual information
@Noah-vm8id
@Noah-vm8id 2 жыл бұрын
0:30 Well for comparing wheels and squares we always want to build a bike right xD?
@anilbarad1856
@anilbarad1856 2 жыл бұрын
Great bro ,i can't understood anything 😂
@igboman2860
@igboman2860 2 жыл бұрын
How does one load balance websockets if the connection is stateful
@jeroendeclercq7580
@jeroendeclercq7580 2 жыл бұрын
Sticky sessions. Make shure the visitor stays on the same server during the entire visit.
@RAMMY237
@RAMMY237 2 жыл бұрын
6:49 Getting popular? I thought it was getting popular about 10 years ago :)
@thiago670
@thiago670 2 жыл бұрын
Nice vídeo, just a little improvement for the next ones. You passed in about 5 minutes in rest API topic and two minutes about the web sockets. Try to balance it as much as possible.
@BeABetterDev
@BeABetterDev 2 жыл бұрын
Thanks for the suggestion Thiago!
@romantheroman98
@romantheroman98 2 жыл бұрын
Why is this only coming now, it seems like it is such a basic logic. Why didn’t they invented that in the 80s or 90s?
@Leostr
@Leostr 2 жыл бұрын
Sorry but chatting app seems to be an example where you need something like websockets. Nothing about comparation of architrctures
@gregd6022
@gregd6022 2 жыл бұрын
It's funny how the whole "web world" which is considered "high tech" is decades behind regular programming world, sockets are something only now get wide spread support (new).. wow.. along with "typescript".. welcome to the 80s..
@RobertSmith-ch9jj
@RobertSmith-ch9jj 2 жыл бұрын
Ye jest, but it’s actually rather impressive. The web is now being used for things far beyond what was intended when the original protocols were designed.
@sc0or
@sc0or 2 жыл бұрын
REST is an architecture, websocket is a transport. How can you make a comparison? Even RESTful is just an API that uses REST constraints. I would understand if you compare HTTP vs WebSocket.
@nimblesheepvenomous3811
@nimblesheepvenomous3811 2 жыл бұрын
why can't you do a REST API, but have the client application own a small api as well? And then when the server has an update to give to the client, the server can do a POST call to the client.
@patheddles4004
@patheddles4004 2 жыл бұрын
Primarily because that would violate the entire client-server model. Like if you're going to do anything like that, then whatever you're implementing on the client side isn't an API, and realistically you're probably just making a bad homebrew equivalent of websockets. And on a practical level, the server would have to be able to initiate connections with John and Mary. That would require John and Mary to each have their own publicly-accessible URI, which for normal home users is a terrible idea and thankfully very rare.
@giancarloandrebravoabanto7091
@giancarloandrebravoabanto7091 2 жыл бұрын
and REST stands for ?
@patheddles4004
@patheddles4004 2 жыл бұрын
REpresentational State Transfer.
@arsiveparkour6251
@arsiveparkour6251 2 жыл бұрын
Why would i use Rest APIs for such applications ? Your explanation was good, but didn't justify the title
@JoseDlucca
@JoseDlucca 2 жыл бұрын
Actually I think the idea of this video it was to show why you shouldn't use Rest API in this type of apps and why web sockets work better in this case
@arsiveparkour6251
@arsiveparkour6251 2 жыл бұрын
@@JoseDlucca that'd have made sense. Anyways, not complaining about this explanation, just felt the title should have been a little more appropriate.
@JoseDlucca
@JoseDlucca 2 жыл бұрын
@@arsiveparkour6251 I agree, the title could be better
@bewhee
@bewhee 2 жыл бұрын
An API is a collection, not a single endpoint like /message. Use the correct terms!
@W_0_W
@W_0_W 2 жыл бұрын
Compared to any socket-based protocols, the REST API looks like something broken / horribly designed. I don't understand why is still exists.
@W_0_W
@W_0_W 2 жыл бұрын
Basically it's a self-ddosing tool.
@patheddles4004
@patheddles4004 2 жыл бұрын
For continuous-ish realtime communication like this, yeah sure sockets make way more sense than REST. For other applications, not so much. I've spent quite a bit of my career developing and consuming REST APIs though, and I can confirm that in a lot of cases they make /way/ more sense than anything socket-based. REST just looks bad here because, in order to make a direct comparison, this video had to use an example where REST doesn't make much sense. REST APIs are everywhere, seriously, and almost none of them could usefully be replaced by sockets.
@nickolajarjous2639
@nickolajarjous2639 2 жыл бұрын
Push notifications
@ArndBrugman
@ArndBrugman 2 жыл бұрын
Most biased example evah
@Pablo-hp2jp
@Pablo-hp2jp 4 ай бұрын
Sehr oberflächlich. Schade
@mahdikhansari3281
@mahdikhansari3281 5 ай бұрын
Amazing explanation
What is API Idempotency and Why Is It Important?
12:13
Be A Better Dev
Рет қаралды 38 М.
Best father #shorts by Secret Vlog
00:18
Secret Vlog
Рет қаралды 21 МЛН
50 YouTubers Fight For $1,000,000
41:27
MrBeast
Рет қаралды 95 МЛН
How Web Sockets work | Deep Dive
10:22
ByteMonk
Рет қаралды 8 М.
How and Why Prime Video Tech Switched From Serverless to "Monolith"
19:58
When RESTful architecture isn't enough...
21:02
Dreams of Code
Рет қаралды 246 М.
The IDEAL & Practical CI / CD Pipeline - Concepts Overview
22:36
Be A Better Dev
Рет қаралды 469 М.
API vs. SDK: What's the difference?
9:21
IBM Technology
Рет қаралды 1,4 МЛН
Don't Use Websockets (Until You Try This…)
6:46
Code With Ryan
Рет қаралды 289 М.
What is DATABASE SHARDING?
8:56
Gaurav Sen
Рет қаралды 908 М.
No-Nonsense Backend Engineering Roadmap
10:16
Codebagel
Рет қаралды 177 М.
WebSockets Crash Course - Handshake, Use-cases, Pros & Cons and more
47:33
Best father #shorts by Secret Vlog
00:18
Secret Vlog
Рет қаралды 21 МЛН