YouTube2Text

5. Understanding HTTP for backend engineers, where it all starts — Transcript

by Sriniously · 12,458 words · 1,812 segments · language en · Watch on YouTube

Full transcript

  1. 0:00backend is huge and if we start
  2. 0:02discussing every single component that
  3. 0:04could be part of it we will be stuck
  4. 0:05here for years so what we will do is we
  5. 0:08will only discuss those topics which are
  6. 0:10used in majority of the code bases let's
  7. 0:13say 90% of them with that in mind let's
  8. 0:15talk about HTTP protocol the medium
  9. 0:18through which our browsers talk to our
  10. 0:20servers either to send data or to
  11. 0:22receive data from it and as I said there
  12. 0:24are a lot of other ways and protocols
  13. 0:27which clients and servers use to
  14. 0:29communicate with each other and HTTP
  15. 0:32being one of the most used ones we will
  16. 0:34focus on that now there are two ideas
  17. 0:36which are at the heart of HTTP protocol
  18. 0:39the first one being tessness what does
  19. 0:42it mean tessness basically means it has
  20. 0:46no memory of past interactions so each
  21. 0:49HTTP request carries all the necessary
  22. 0:52information for the server to process it
  23. 0:54such as headers or URLs and methods
  24. 0:57which we will see in a bit and after the
  25. 0:58server responds it forgets about the
  26. 1:00request if a client makes another
  27. 1:02request the server treats it as a new
  28. 1:05and unrelated event and it also means
  29. 1:08self-contained requests since the server
  30. 1:10does not remember pass requests each
  31. 1:12request must include all the necessary
  32. 1:15data such as authentication tokens or
  33. 1:17session information to handle that
  34. 1:20specific interaction for example in the
  35. 1:22case of accessing a user profile the
  36. 1:24client has to provide credentials like
  37. 1:27cookies or tokens on every request for
  38. 1:29for the server to know which user is
  39. 1:31requesting the data so what are the
  40. 1:34benefits of that what are the benefits
  41. 1:36of this stateless model the obvious one
  42. 1:38being Simplicity stateless design
  43. 1:41simplifies server architecture because
  44. 1:43the server does not need to store
  45. 1:45session information which would
  46. 1:46otherwise require additional resources
  47. 1:48and complexity and it also means
  48. 1:51scalability stateless protocol makes it
  49. 1:54easy to distribute request across
  50. 1:56multiple servers because no single
  51. 1:59server need needs to keep track of a
  52. 2:01session and if the server crashes it
  53. 2:03does not affect the state of a client
  54. 2:05interaction as there is no session or
  55. 2:08memory of a request that needs to be
  56. 2:09restored and having said that because
  57. 2:13HTTP is stateless developers often
  58. 2:15Implement State management techniques
  59. 2:17like cookies or sessions or tokens to
  60. 2:20maintain continuity in interactions
  61. 2:23where needed like user logins or
  62. 2:26shopping cards and we'll explore those
  63. 2:28soon in this series and the second idea
  64. 2:31is client server model in a typical HTTP
  65. 2:34request flow there is a client and there
  66. 2:36is a server always the client typically
  67. 2:39is a web browser or an application which
  68. 2:42initiates the communication by sending a
  69. 2:44request to the server the client is
  70. 2:46responsible for for providing all
  71. 2:49information needed by the server such as
  72. 2:51the URL of the resource or the headers
  73. 2:54and
  74. 2:55everything and then there is a server
  75. 2:59which hosts resources like websites or
  76. 3:01apis or other content and waits for
  77. 3:04incoming requests from the clients when
  78. 3:07the server receives a request it
  79. 3:08processes it and sends back the
  80. 3:11appropriate response such as a web page
  81. 3:13or data or error message or a Json file
  82. 3:17or a text file or any other kind of
  83. 3:19content now the thing to remember here
  84. 3:21is HTTP protocol states that
  85. 3:24communication is always initiated by the
  86. 3:27client to get some kind of resp response
  87. 3:30by the server and throughout our
  88. 3:32discussion we can go ahead and safely
  89. 3:35assume that HTTP and https are
  90. 3:38interchangeable because https to
  91. 3:41oversimplify it just a more secure
  92. 3:44version of HTTP but the underlying
  93. 3:46principles are the same with more
  94. 3:48security features like encryption and
  95. 3:51security certificates or TLS stuff like
  96. 3:54that which boarders too much into the
  97. 3:56network engineering domain also to send
  98. 3:59some kind of request or receive some
  99. 4:01kind of response first the client and
  100. 4:04the server need to establish some kind
  101. 4:07of connection mechanism right otherwise
  102. 4:10how are they going to communicate what
  103. 4:11is the medium of the communication and
  104. 4:13for that sgtp uses TCP
  105. 4:17TCP which is a protocol which is a
  106. 4:20transmission protocol essentially HTTP
  107. 4:22does not require the underlying
  108. 4:24transport protocol to be connection
  109. 4:26based it only requires it to be reliable
  110. 4:28and not lose message messages at minimum
  111. 4:31presenting an error in such cases and
  112. 4:33among the two most common transport
  113. 4:34protocols on the internet which are TCP
  114. 4:37and UDP TCP is considered to be more
  115. 4:40reliable HTTP therefore relies on the
  116. 4:42TCP standard which is connection based
  117. 4:45now this is called an OSI model which is
  118. 4:48often referred when we are talking about
  119. 4:50sending and receiving data over a
  120. 4:52network right and we as backend
  121. 4:55Engineers often deal with this layer the
  122. 4:58top layer the layer 7even application
  123. 5:01layer and so a lot of discussions for
  124. 5:05example the recent one which we talked
  125. 5:07about the TCP handshake and establishing
  126. 5:10connections and TLS encryptions they
  127. 5:13often border into these
  128. 5:15layers so they are mostly network
  129. 5:19engineering concepts of course it's it's
  130. 5:22good to know about those but if we start
  131. 5:24exploring those it'll be a rabbit hole
  132. 5:26and we'll have to cover a lot of
  133. 5:28Concepts right so what we'll do is we'll
  134. 5:31focus on the application layer with a
  135. 5:33brief about you know what happens in the
  136. 5:35netor layer like as I said HTTP uses TCP
  137. 5:39and TCP uses something like a 3-way
  138. 5:42handshake which if you're curious about
  139. 5:44you can just look up and study more on
  140. 5:47that now throughout the years we had
  141. 5:49different versions of HTTP which kept
  142. 5:52redefining how clients and servers send
  143. 5:54and receive data right in sttp 1.0 each
  144. 5:58request opened a new connection this led
  145. 6:01to inefficiencies since a connection had
  146. 6:03to be established and closed for every
  147. 6:05request and response which slowed
  148. 6:07performance in HTTP 1.1 they introduced
  149. 6:11something called as persistent
  150. 6:12connections allowing multiple request
  151. 6:15and responses over the same connection
  152. 6:17over the same TCP connection that was
  153. 6:19established before sending the request
  154. 6:21which significantly improved performance
  155. 6:23it also added stuff like chunk transfer
  156. 6:26encoding and better caching mechanisms
  157. 6:29in SCP 2.0 they introduced multiplexing
  158. 6:32allowing multiple requests or responses
  159. 6:34over a single collection it uses
  160. 6:36something called binary framing instead
  161. 6:38of text and supports header compression
  162. 6:40with Edge pack or and server push
  163. 6:43allowing servers to send resources
  164. 6:45before the client requests them now in
  165. 6:47sttp 3.0 built on quick protocol a
  166. 6:51transport layer protocol over UDP right
  167. 6:54instead of TCP it is designed over UDP
  168. 6:56which improved performance with faster
  169. 6:59connection establishment reduce latency
  170. 7:01and better handling of packet loss it
  171. 7:04also continues to support multiplexing
  172. 7:06without head ofline blocking which is
  173. 7:08still an issue in HTTP 2.0 now again
  174. 7:11that's a rabbit hole if you get too much
  175. 7:13into the network stuff all we need to
  176. 7:16remember is that from all these
  177. 7:18discussions that client and servers
  178. 7:21established some kind of network
  179. 7:23connection and messages are sent and
  180. 7:26received that's all you need to remember
  181. 7:29for now now that we mentioned message
  182. 7:31let's look at what HTTP messages look
  183. 7:34like request messages or response
  184. 7:36messages a request message is basically
  185. 7:39the one that is sent by the client and a
  186. 7:41response message is the one that is
  187. 7:43received by the client from the server
  188. 7:45so this is what a request message looks
  189. 7:47like in HTTP and this is what a response
  190. 7:51message looks like I intentionally took
  191. 7:53more complex messages which had more
  192. 7:56parameters and so that we can cover
  193. 7:58different different components one by
  194. 8:00one so on a high level I'll just explain
  195. 8:02what is what in this right this part
  196. 8:05this is called a request method this is
  197. 8:07the resource URL the one we are
  198. 8:09requesting from the server this is the
  199. 8:11HTTP version which says we are using
  200. 8:14HTTP version 1.1 which is the currently
  201. 8:16the most used one this is the host right
  202. 8:21which is our
  203. 8:22domain the front ends domain and these
  204. 8:26are this all of these things these are
  205. 8:29called headers right we will talk about
  206. 8:32headers soon there will be a blank line
  207. 8:34here after all the headers to signify
  208. 8:36that the headers are over and body
  209. 8:39starts this is called a request body
  210. 8:42some information the client wants to
  211. 8:45send to a server right and in the
  212. 8:48response message again we have the HTTP
  213. 8:51version have the status code and the
  214. 8:55value of the status code which basically
  215. 8:56means the status code 200 means okay
  216. 8:59right and we have again some response
  217. 9:02headers after that there is a blank line
  218. 9:05and we have the response
  219. 9:07body so let's talk about HTTP headers
  220. 9:11first this is very important since it's
  221. 9:14the major part of the request here and
  222. 9:16the responses on a high level what we
  223. 9:18can see is headers are basically key
  224. 9:20value pairs key value pairs of different
  225. 9:22different parameters that is sent over
  226. 9:25request or received over a response that
  227. 9:28is the first definition and the next
  228. 9:30question is why do we need headers why
  229. 9:33not send the all these values in the you
  230. 9:36know the URL or we have this request
  231. 9:39body here why send why create a
  232. 9:41different section just for sending more
  233. 9:44information or more met data about the
  234. 9:46request or the response why create
  235. 9:49another level of abstraction and in
  236. 9:51order to understand that let's take a
  237. 9:53real life example we send Parcels right
  238. 9:56ciers and we receive them the address of
  239. 9:59about the phone number of the recipient
  240. 10:02and different details right the the
  241. 10:04state the the PIN code and all of these
  242. 10:07things do we keep it inside the package
  243. 10:11or do we write it on top and we write it
  244. 10:14on top why because the one who is taking
  245. 10:19the parcel from the sender and to the
  246. 10:22receiver they need to know different
  247. 10:24informations in order to
  248. 10:26successfully transmit the package
  249. 10:29through different modes of transmission
  250. 10:32and if we kept all those information
  251. 10:35inside the parcel they have to open that
  252. 10:38right and which does not make any sense
  253. 10:42but just for the sake of the example
  254. 10:43they have to open that and they have to
  255. 10:45see who is the recipient again and again
  256. 10:47so let's say another person wants to see
  257. 10:50the address so again they have to open
  258. 10:52that so keeping the metadata the address
  259. 10:56and the information of the recipient on
  260. 10:58top of the parel uh gives a quick way of
  261. 11:02checking different metadata about the
  262. 11:04package sdtp headers can be thought of
  263. 11:06something like that but they have more
  264. 11:08uses before we go into the use cases
  265. 11:11let's see what are some different kinds
  266. 11:13of headers that we see so as you can see
  267. 11:16there are a lot of different types of
  268. 11:17headers so can we categorize them can we
  269. 11:20categorize them and different types of
  270. 11:21headers so let's see the first category
  271. 11:24can be request headers which are sent by
  272. 11:26the client to the server to provide some
  273. 11:28kind of information about the request
  274. 11:30itself it could be user agent which
  275. 11:32identifies what kind of client is that
  276. 11:35it is a browser or it is a it is Postman
  277. 11:39or it is some kind of server or it's a
  278. 11:42mobile app we have authorization which
  279. 11:44sends different credentials like bar
  280. 11:46token to the server to identify the user
  281. 11:49you have accept headers which provides
  282. 11:52informations like what kind of content
  283. 11:54we are expecting whether it is a Json
  284. 11:56whether it is a text whether it is an
  285. 11:58HTML file so request headers help server
  286. 12:02understand the client's environment its
  287. 12:04preferences and its capabilities then we
  288. 12:07have General headers which are used in
  289. 12:09both request and responses which have
  290. 12:12some metadata about the message itself
  291. 12:15for example the date of the message and
  292. 12:18different caching mechanisms like no
  293. 12:20cache or max age and the connection
  294. 12:24information whether to keep it alive or
  295. 12:26to close it so General header have some
  296. 12:29kind of information about the request
  297. 12:32message or the response message then we
  298. 12:34have representation headers which
  299. 12:35primarily deal with the representation
  300. 12:37of the resource being transmitted
  301. 12:39whether it could be a request body or a
  302. 12:42response message the content type
  303. 12:44describes the media type of the request
  304. 12:47or the response it could be Json or it
  305. 12:49could be HTML the content length describ
  306. 12:52the size of the resource in bites the
  307. 12:54content encoding specifies any encoding
  308. 12:57like G or D flare then we have eag a
  309. 13:00unique identifier which is mostly used
  310. 13:03for caching so representation headers
  311. 13:06provides information about the body of
  312. 13:08the message or the response ensuring the
  313. 13:10clients and servers know how to
  314. 13:12interpret and process request or the
  315. 13:15response then we have security headers
  316. 13:17which are used to enhance the security
  317. 13:18of the request and response by
  318. 13:20controlling behaviors like content
  319. 13:22loading cookies and encryption hsts
  320. 13:25ensures that the client only
  321. 13:26communicates with the server over https
  322. 13:29preventing protocol downgrade attack
  323. 13:31content security policy restricts the
  324. 13:33sources from which content like
  325. 13:35JavaScript or css and images can be
  326. 13:37loaded helping prevent cross site
  327. 13:39scripting attacks x-frame options
  328. 13:41prevents the web page from being
  329. 13:43embedded in iframe mitigating
  330. 13:44clickjacking attack X content type
  331. 13:46options ensures that the browser does
  332. 13:49not try to guess the mime type of the
  333. 13:51content preventing MIM type sniffing
  334. 13:53attack that cookie with HTTP only or
  335. 13:55secure Flags secures cookies by making
  336. 13:58them inaccessible with JavaScript and
  337. 14:00ensuring they are sent over https so
  338. 14:02security headers helps protect the
  339. 14:05client and server from a variety of
  340. 14:07attacks by controlling how the browser
  341. 14:09behaves with resources and enforcing
  342. 14:12security policies now there are two
  343. 14:14ideas that we see here while talking
  344. 14:16about HTTP headers one is
  345. 14:19extensibility HTTP is highly extensible
  346. 14:23because headers can be easily added or
  347. 14:25customized without altering the
  348. 14:27underlying protocol
  349. 14:29right we only have to add some kind of
  350. 14:32metadata and the whole flow of the
  351. 14:34interaction changes depending on that
  352. 14:37now headers can be defined and used for
  353. 14:39various purposes making HTTP adaptable
  354. 14:42to new technologies and use cases for
  355. 14:44instance security enhancements as we
  356. 14:46just talked about headers like strict
  357. 14:47Transport Security and Force Security
  358. 14:49connections custom headers developers
  359. 14:51can create custom headers like X custom
  360. 14:54header for specific application for
  361. 14:57their own use cases content negotiation
  362. 14:59the accept and the accept language and
  363. 15:02accept encoding headers allows servers
  364. 15:04to serve different versions of the
  365. 15:05content depending on the client's
  366. 15:07preference so the next part is the idea
  367. 15:09of remote control sgtp headers act as
  368. 15:12kind of a remote control on the server
  369. 15:14side they allow the client to send
  370. 15:17instructions or preferences to the
  371. 15:19server influencing how the server
  372. 15:22responds or processes requests for
  373. 15:24example content Ty negotiations clients
  374. 15:28can request specific formats using
  375. 15:30accept header and the server can respond
  376. 15:32with the appropriate format if the
  377. 15:33client says I want the HTML format the
  378. 15:36server sends the HTML and if the client
  379. 15:38says they want Json then the server
  380. 15:40sends the Json format then caching and
  381. 15:43expiration control the server can use
  382. 15:46headers like cach control or expires to
  383. 15:48control how long a resource should be
  384. 15:51cached by the client then authentication
  385. 15:54the client can authenticate itself to
  386. 15:56the server through authorization header
  387. 15:58influencing Access Control decisions
  388. 16:00right so these provide more capabilities
  389. 16:04on top of our messages which are very
  390. 16:07useful in a lot of instances now we have
  391. 16:10some kind of idea about the headers in
  392. 16:12HTTP and we will explore them in more
  393. 16:16depth when we are going through the
  394. 16:18demos let's move on to the next
  395. 16:19component of a HTTP message right the
  396. 16:22HTTP method HTTP methods exist to
  397. 16:25represent different kinds of actions
  398. 16:28that a CL client like a browser or an
  399. 16:30API consumer can request on a server
  400. 16:33instead of every request doing the same
  401. 16:35thing methods Define the
  402. 16:38intent the keyword note here is the
  403. 16:42intent the intent of the
  404. 16:45interaction this gives clear semantic
  405. 16:49meaning to each type of action and it is
  406. 16:52pretty intuitive in that sense we use
  407. 16:55get request to fetch some kind of data
  408. 16:57from the server and it should not modify
  409. 17:00anything on the server use post to
  410. 17:02create some data in the server and post
  411. 17:04request have a body which makes sense
  412. 17:07because how else would you send the user
  413. 17:08data to the server then we have
  414. 17:12patch which is used to update some data
  415. 17:15for example you have a users profile
  416. 17:17page where they can update their name
  417. 17:19and this also has a request body to send
  418. 17:22the data to the server we also have put
  419. 17:26which is also used to update data but
  420. 17:29what sets it apart from patch is
  421. 17:31whatever data that comes in request body
  422. 17:33should completely replace the previous
  423. 17:36instance basically patch can be thought
  424. 17:38of as an append action or a selective
  425. 17:40replacement while put is a complete
  426. 17:43replacement even though a lot of times
  427. 17:45developers use put when they should be
  428. 17:47using patch and go against the semantics
  429. 17:51so the thumb rule is always use patch
  430. 17:53unless you have a specific use case for
  431. 17:56put then we have delete method and as
  432. 17:58the name suggests we use this to delete
  433. 18:01some kind of resource from the server
  434. 18:03and one prevalent idea that we have in
  435. 18:07the context of HTTP methods is the idea
  436. 18:10of EMP poent and nonm poent and what the
  437. 18:14idea of important means is these HTTP
  438. 18:18methods can be called multiple times and
  439. 18:21we can expect the same kind of result
  440. 18:23for example we generally consider the
  441. 18:26methods get or put
  442. 18:30or
  443. 18:31delete in the category of it poent
  444. 18:34methods because just think about it
  445. 18:37you're trying to fetch some data from
  446. 18:39the server right it does not matter how
  447. 18:41many times you fetch it the data should
  448. 18:43be same you should not be able to modify
  449. 18:46any kind of data in the server so get is
  450. 18:49obviously impotent and then we have put
  451. 18:52because put completely replaces the
  452. 18:54resource in the server so it does not
  453. 18:56matter how many times you replace an old
  454. 18:59with the new data it will the result
  455. 19:02will be the same right so that is also
  456. 19:04considered as important then we have
  457. 19:06delete you can only delete a resource
  458. 19:09from the server once because after that
  459. 19:11it is already deleted you cannot perform
  460. 19:13the action multiple times and expect
  461. 19:15different results right the result will
  462. 19:17always be the same the resource can only
  463. 19:19be deleted once and then we have the
  464. 19:22idea of nonmutant usually we consider
  465. 19:26post request to be non important because
  466. 19:30once you submit a request to create some
  467. 19:33data let's
  468. 19:34say uh a user can create a note using
  469. 19:37your app right they submitted a post
  470. 19:40request to create a new note and the
  471. 19:43first time they submit the request the
  472. 19:45request goes through the response is
  473. 19:46successful and a new note is created and
  474. 19:50when they do it a second time we create
  475. 19:52a new note right there are two different
  476. 19:55results for the same kind of request so
  477. 19:58that's why we consider post to be a
  478. 20:00non-idempotent method because it
  479. 20:03produces different results for the same
  480. 20:05kind of request after all the sgtp
  481. 20:08methods we have one other method which
  482. 20:10is called the options method and this
  483. 20:12has a very interesting use case which is
  484. 20:15used in the course flow right we
  485. 20:18discussed this before in brief the
  486. 20:22course flow which is part of the same
  487. 20:25origin policy which browsers have now
  488. 20:28options method this method you probably
  489. 20:31won't use directly as a developer but
  490. 20:34you will see them once in a while in
  491. 20:35your browser network tab in pre-flight
  492. 20:38requests so the options method is used
  493. 20:40to fetch the capabilities of the server
  494. 20:44for a cross origin request also known as
  495. 20:47course which is used because browsers
  496. 20:50have same origin policy which means by
  497. 20:52default browsers follow the same origin
  498. 20:55policy which restricts web pages from
  499. 20:58making requests to a domain different
  500. 21:01from theirs different from the one
  501. 21:03serving the web page and course is a
  502. 21:06security mechanism enforced by browsers
  503. 21:09to control how web applications interact
  504. 21:12with resources hosted on different
  505. 21:14domains which are cross
  506. 21:16origin and without course browsers block
  507. 21:21the request made from a web application
  508. 21:23running on one origin like example.com
  509. 21:26to a different origin like API another
  510. 21:29example.com for security reasons course
  511. 21:31allows servers to specify who can access
  512. 21:35their resources and how in a cross
  513. 21:37origin request there are primarily two
  514. 21:40types of flows one is a simple request
  515. 21:42flow and another one is a pre-f flighter
  516. 21:44request flow first let's look at the
  517. 21:46simple request imagine our client our
  518. 21:48frontend is at the Domain example.com
  519. 21:51and our server is at the Domain api.
  520. 21:54example.com and we make a get request
  521. 21:57which looks something like like this
  522. 21:59this is how the flow looks like the
  523. 22:00client sends a request the browser
  524. 22:03automatically adds the origin header to
  525. 22:05indicate the origin of the request the
  526. 22:07request uses a simple method which are
  527. 22:09usually get post or head and then it
  528. 22:13reaches the server the server checks for
  529. 22:16the origin header against it C policy if
  530. 22:19the origin is
  531. 22:21allowed the server includes the access
  532. 22:24control allow origin header in the
  533. 22:26response and it sends the response
  534. 22:28response the server responds with the
  535. 22:30resource and includes the necessary
  536. 22:32course headers for example Access
  537. 22:34Control allow origin header and this is
  538. 22:36what the response looks like it has the
  539. 22:38appropriate course header which the
  540. 22:40browser looks for while it passes the
  541. 22:42response it sees that our domain which
  542. 22:45is the example.com is different from the
  543. 22:47host domain which is the api. another
  544. 22:50domain.com and since these two are
  545. 22:53different the browser checks whether the
  546. 22:55server's response has this header or not
  547. 22:58whether it responds with this particular
  548. 23:00header Access Control allow origin if
  549. 23:03the server responds with the domain of
  550. 23:06the client example.com or it could also
  551. 23:09respond with star which means allow all
  552. 23:12Origins right if either of those two
  553. 23:15conditions are true then the browser
  554. 23:17lets the response go through to the
  555. 23:20client to whatever the JavaScript client
  556. 23:22requesting the resource and imagine
  557. 23:25imagine if the response looked like this
  558. 23:27the client sent the request the server
  559. 23:29got the request and assuming the server
  560. 23:32did not add the corresponding course
  561. 23:35headers or assuming the server did not
  562. 23:37allow this particular domain as the
  563. 23:40client then what the server does it
  564. 23:43excludes this particular header from the
  565. 23:46response so the response looks something
  566. 23:48like this and when the browser finally
  567. 23:50parses it it sees that it sees the
  568. 23:52absence of this header and what it does
  569. 23:55it blocks the this particular response
  570. 23:58from being passed you will get an error
  571. 24:00in our console and we will see the error
  572. 24:02in the network tab as a course error and
  573. 24:06this is how a simple request flow looks
  574. 24:08like next we have a pre-lighted request
  575. 24:11flow for a cross origin request and how
  576. 24:15does a browser distinguish between a
  577. 24:17simple request flow and a pre-lighted
  578. 24:20request flow so these are the three
  579. 24:22conditions the browser checks before it
  580. 24:25decides it has to do a PF flight request
  581. 24:28which basically means it has to do a
  582. 24:30request before the original request to
  583. 24:32inquire some stuff to inquire some
  584. 24:35capabilities and to let the server know
  585. 24:37about some capabilities right and when
  586. 24:39does a request qualify as a pre-lighted
  587. 24:42request one is the method is not get
  588. 24:46post or head example it is a put request
  589. 24:48or a delete request and it is a either
  590. 24:51or situation right it either of these
  591. 24:54conditions have to be true then it will
  592. 24:55be considered as a pre-lighted request
  593. 24:58so the first condition is obviously it
  594. 25:00has to be cross Surin request which
  595. 25:01means our domain and the server domain
  596. 25:04has to be different and the second
  597. 25:06condition is one of these three and
  598. 25:08after that it will be a c request and
  599. 25:11inside that it will be a pre-lighted
  600. 25:13request so the first condition is it has
  601. 25:15to be either a put request or a delete
  602. 25:17request or the request includes some
  603. 25:20nons simple headers nons simple headers
  604. 25:23are basically anything apart from our
  605. 25:26general headers or request headers so
  606. 25:28one example could be an authorization
  607. 25:30header or some custom headers right and
  608. 25:33the third one is or the request has a
  609. 25:37content type other than application form
  610. 25:41URL encoded or multiart or text plan
  611. 25:45these are called General content types
  612. 25:48or simple content types so if assuming
  613. 25:51our application our client request the
  614. 25:55data to be in Json
  615. 25:58in that case it will be considered as a
  616. 26:00pre-lighted request and if you are a
  617. 26:02frontend engineer or a backend engineer
  618. 26:04you know that mostly we deal with Json
  619. 26:06data right so most of our requests are
  620. 26:08considered as a pre-lighted requests
  621. 26:11these are the three conditions either of
  622. 26:13them have to be satisfied before we move
  623. 26:16on before the browser moves on to make a
  624. 26:18pre-flight request what does a
  625. 26:20pre-flight request looks like this is
  626. 26:23when we finally see the use of options
  627. 26:25method right a pre-flight request is
  628. 26:28made with an options method and pre-
  629. 26:30flight request looks something like this
  630. 26:33it has the method as options it has the
  631. 26:36appropriate resource URL and the HTTP
  632. 26:39version it has the host header which is
  633. 26:42the header of our API the origin the
  634. 26:45domain of the front end and this header
  635. 26:48Access Control request method so it is
  636. 26:51basically asking the server whether this
  637. 26:54method is supported for this URL or not
  638. 26:57so it is saying I am making a cross
  639. 26:59origin request and do you support this
  640. 27:02put method for this route right and it
  641. 27:06also asks whether you support this
  642. 27:08particular header or not if it is needed
  643. 27:11and the browser sends the options
  644. 27:12request to the server the request does
  645. 27:15not include actual data right this does
  646. 27:17not include any request body or anything
  647. 27:20it is just a general inquiry to the
  648. 27:22server about its capabilities and after
  649. 27:26that if the server is is properly
  650. 27:28handling course flow if the server
  651. 27:31supports cross origin requests it
  652. 27:34responds something like this and if the
  653. 27:36server does not handle cost request then
  654. 27:39it won't respond with this and the
  655. 27:42request will be automatically blocked by
  656. 27:44the browser and if it does handle it it
  657. 27:47requests with something like this what
  658. 27:49it says is this is the status code of
  659. 27:51the response which means there is no
  660. 27:52content this is just a general
  661. 27:54information we use 204 when there is no
  662. 27:57content then these are the four
  663. 27:59important headers it responds with the
  664. 28:02first one is the access control allow
  665. 28:04origin it says yes I allow the client's
  666. 28:08domain which is example.com as a cross
  667. 28:10origin as a valid cross origin request
  668. 28:13right it can either respond with this or
  669. 28:17it can respond with a star which
  670. 28:19basically means I allow all types of
  671. 28:21clients to make request to me this is
  672. 28:23the one valid condition it is browser
  673. 28:26checks it the next is we asked whether
  674. 28:28you allow put request for this resource
  675. 28:31or not so the server says yes I allow
  676. 28:33these two different kinds of methods it
  677. 28:35is the put method and delete method for
  678. 28:38this resource for this particular route
  679. 28:41right and the browser checks it off the
  680. 28:43next one is we asked whether you allow
  681. 28:45authorization header and the server says
  682. 28:47yes I allow authorization header and
  683. 28:49then it is also checked off and the last
  684. 28:52one is Access Control maxage what this
  685. 28:54means is the server says don't make make
  686. 28:58any more pre-flight request to me right
  687. 29:01it says these these configs whatever I
  688. 29:03responded with these will be the same
  689. 29:06for at least the next 24 hours so you
  690. 29:08don't have to keep making more
  691. 29:10pre-flight requests for every route
  692. 29:12before you send the original request so
  693. 29:15this saves some bandwidth for both our
  694. 29:18servers and clients so this is the
  695. 29:19pre-flight request that the browser
  696. 29:21makes and the server responds with the
  697. 29:24appropriate headers the browser checks
  698. 29:25off all these conditions and then the
  699. 29:28browser sends the final request which is
  700. 29:30the original request that the client
  701. 29:32wanted to make and the server responds
  702. 29:34according to the original request with
  703. 29:36whatever the operations are required
  704. 29:39this is how the typical course flow
  705. 29:41looks like and now that we understood
  706. 29:43the theory let let's look at a real demo
  707. 29:46okay now before we start let me make
  708. 29:49this clear that we won't be looking at
  709. 29:51any code because as I said we are
  710. 29:54learning from first principles and the
  711. 29:57rule for that is
  712. 29:58we try to understand the concepts first
  713. 30:01how the underlying mechanism Works
  714. 30:03before we dive into code before we
  715. 30:06understand the how but first we have to
  716. 30:09understand what for all these demos that
  717. 30:12we are going to do in this video and and
  718. 30:14all the other videos in this series we
  719. 30:16won't be looking at any code it does not
  720. 30:19matter what language the server is
  721. 30:22written in what framework it is written
  722. 30:24in I'll explain what I am changing in
  723. 30:27the server what I have done in the
  724. 30:28server for all it matters it can be
  725. 30:30implemented in any language that's that
  726. 30:33and this is a tool it's called burp suit
  727. 30:38and it is used by ethical hackers if you
  728. 30:41may it has a lot of features as you can
  729. 30:44see but primarily what we are going to
  730. 30:46use it for is HTTP intercepting or
  731. 30:50visualizing HTTP traffic and it offers a
  732. 30:54quite a nice set of features for that
  733. 30:56with that what I have here is I have a
  734. 31:00simple front end app again it could be
  735. 31:02in any language and what I want to show
  736. 31:05is one for our course flow one is the
  737. 31:08simple request and one is the pre-light
  738. 31:11request and how they look like in actual
  739. 31:14browser environment so let's fire the
  740. 31:18first simple
  741. 31:20request okay so we got this response
  742. 31:23that we are rendering here and let's
  743. 31:25inspect the request and response for now
  744. 31:28right if you go here this is what the
  745. 31:32request and response looks like right we
  746. 31:35already took a look at all these
  747. 31:36components right the method and the URL
  748. 31:39and all these headers and the response
  749. 31:42the status code and the response headers
  750. 31:44the response body so let's focus on the
  751. 31:47course here what is the first parameter
  752. 31:49for a request to be considered as a
  753. 31:51cross origin request by the browser the
  754. 31:54first thing is the origin so this is our
  755. 31:57local host file
  756. 31:58173 and the host right this is our apis
  757. 32:04which is running on the port 3,000 of
  758. 32:06Local Host since the host and the origin
  759. 32:10are running on different ports in Local
  760. 32:14Host by the browser this is considered
  761. 32:17as a cross origin request and according
  762. 32:20to the same origin policy we can only
  763. 32:22make request from Local Host 5173 to
  764. 32:24Local Host 5173 right since we not it is
  765. 32:29considered as a cross origin request the
  766. 32:31headers to focus here is origin header
  767. 32:34let me minimize
  768. 32:37this so the the headers to focus here is
  769. 32:40the origin header which is our origin
  770. 32:43the front end origin and the host the
  771. 32:46domain or the port that you want to
  772. 32:49connect to which is the apis right for
  773. 32:52the request these are the two important
  774. 32:54headers now let's go to the response now
  775. 32:57the thing to f Focus here is this header
  776. 32:59right as I had explained the browser
  777. 33:02makes a cross origin request and when it
  778. 33:05gets the response it checks whether it
  779. 33:07has the access control allow origin
  780. 33:10header or not or whether it has the
  781. 33:13appropriate port or the domain so it has
  782. 33:16the front ends Port right the
  783. 33:195173 or it could also have star so in
  784. 33:22that case the browser lets the response
  785. 33:25through and and it does not block it
  786. 33:27since according to the core sets this
  787. 33:31response is now expected right this
  788. 33:33response is now allowed and now that's
  789. 33:36why we are able to get the response and
  790. 33:38now we are able to render it in our
  791. 33:40front end right let's see what happens
  792. 33:43if you remove this header like this
  793. 33:46Access Control allow origin header from
  794. 33:48the server for a simple request let me
  795. 33:51just go and make this change okay I have
  796. 33:53went ahead and made the change in the
  797. 33:55server now it won't return the appri
  798. 33:57corer Access Control allow origin Let me
  799. 34:00refresh
  800. 34:01this and let's clear this history so
  801. 34:04that we can focus on the particular
  802. 34:06request now let's fire the same request
  803. 34:08again and before we do let's disable
  804. 34:10caching so that we can see what a new
  805. 34:14request looks like right so let me fire
  806. 34:16this the browser blocked this response
  807. 34:19right it says course error and why let's
  808. 34:22inspect this request and response so
  809. 34:26here if you see we have a cross origin
  810. 34:29request because our origin is 5173 and
  811. 34:32the host is 3001 and the server does not
  812. 34:37return an access control allow origin
  813. 34:39header right because we removed it and
  814. 34:41for that reason the browser has blocked
  815. 34:44the request because of course error so
  816. 34:47this is how the simple request flow
  817. 34:49looks like and now let's move on to our
  818. 34:51pre-lighted request right okay I have
  819. 34:53gone ahead and enabled the course again
  820. 34:55so that we can test the pre-flight
  821. 34:57request flow okay let me fire
  822. 35:02this all right as you can see here the
  823. 35:06first request that went through was the
  824. 35:08options request right the pre-flight
  825. 35:11request and then the original request
  826. 35:13went through let's look at them one by
  827. 35:15one how the whole flow looked like okay
  828. 35:18for the pre-flight request as we have
  829. 35:20already discussed the method was options
  830. 35:23and it is a cross origin request because
  831. 35:26the referrer and the origin are
  832. 35:29different ports right and for
  833. 35:32that what the server responded with it
  834. 35:35responded with status code 204 no
  835. 35:38content because it is just a general
  836. 35:40inquiry right pre-flight requests are
  837. 35:42General inquiries they don't have
  838. 35:44request bodies or response bodies and
  839. 35:47the server responded with Access Control
  840. 35:49allow origin with the front ends domain
  841. 35:53or Port right this makes the browser
  842. 35:56allow the response wants to go through
  843. 35:58that is the first condition and before
  844. 36:01that let's see why a pre-flight request
  845. 36:03was fired right why why this was not
  846. 36:05considered a simple request he
  847. 36:07investigate the original request what
  848. 36:09was the conditions it is not a simple
  849. 36:11method which is get post or head right
  850. 36:14that is that was one of the conditions
  851. 36:16so it is already satisfied but let's
  852. 36:18look at others it also has a
  853. 36:20authorization header that also counts it
  854. 36:22out of a simple request right that is
  855. 36:25the second one and the third one is the
  856. 36:29content type is application Json and it
  857. 36:31is sending a Json request body right all
  858. 36:34the three conditions are satisfied but
  859. 36:36even if one of them was satisfied it
  860. 36:39would have still fired a pre-flight
  861. 36:40request for this let's go back to our
  862. 36:43options pre-light request analysis the
  863. 36:46first one was it allowed the client's
  864. 36:49domain so that the browser lets the
  865. 36:51response to go through the second
  866. 36:54one Access Control allowed methods so
  867. 36:57the server says all these methods get
  868. 37:00post put delete these methods are
  869. 37:02allowed for the server it lets the
  870. 37:04client know the capabilities of the
  871. 37:06server the third thing is Access Control
  872. 37:09allowed headers it says these are the
  873. 37:11two headers which are not simple headers
  874. 37:14that are supported by the server which
  875. 37:16is the content type and authorization
  876. 37:19since the client asked for them if you
  877. 37:22look at this Access Control request
  878. 37:25method put the client is asking with the
  879. 37:28pre-flight request whether the put
  880. 37:29method is allowed or not and whether the
  881. 37:32these two headers authorization and
  882. 37:34content type these two headers are
  883. 37:37allowed or not so for that the server is
  884. 37:39responding with these headers it says
  885. 37:42get post put delete is allowed it also
  886. 37:44says content type and authorization is
  887. 37:46also allowed we have also set the max
  888. 37:48age for the access control to zero for
  889. 37:51testing purposes right because if you
  890. 37:53cach this for let's say 5 minutes then
  891. 37:56pre-flight request be fired that's why
  892. 37:59this is used for and the content length
  893. 38:01is zero because there is no content
  894. 38:03since the pre-flight request was
  895. 38:05successful it returned 204 it is a
  896. 38:08success status code the browser let the
  897. 38:10response go through and it fired the
  898. 38:13original request it is the put method
  899. 38:15and this is the original request it has
  900. 38:18put method the resource URL the origin
  901. 38:22and the authorization header the host
  902. 38:25the request body and it responded with a
  903. 38:29response body right and that's how the
  904. 38:32pre-flight request flow looks like so
  905. 38:34the simple request and the pre-flight
  906. 38:36request flow combined they make the
  907. 38:39whole course flow and this is all you
  908. 38:42have to understand how course Works
  909. 38:44behind the scenes and why these headers
  910. 38:46are important and how browsers react to
  911. 38:50them okay moving on the next component
  912. 38:53that I want to cover is response codes
  913. 38:55this part this 200 okay what are these
  914. 39:00and why are they needed HTTP response
  915. 39:03codes exist to communicate the result of
  916. 39:05a request in a standardized way know you
  917. 39:08can just look at the response code and
  918. 39:10see whether the request was successful
  919. 39:13or not or what is the state of the
  920. 39:15server without looking into the body or
  921. 39:18without judging from the response
  922. 39:19message that okay so if the request was
  923. 39:22successful then I would have expected
  924. 39:24this structure if the request was
  925. 39:25unsuccessful then I would have expected
  926. 39:27this structure if the server crashed
  927. 39:29then I would have expected a null object
  928. 39:32right we don't have to make those
  929. 39:34decisions we can judge by these status
  930. 39:37Cotes so they quickly inform the client
  931. 39:40whether the request was successful
  932. 39:42resulted in an error or requires further
  933. 39:45action they also help clients handle
  934. 39:47errors by providing specific codes to
  935. 39:49identify the problem for example
  936. 39:51unauthorized access will return 401 so
  937. 39:54now the clients can check whether it is
  938. 39:5640 one and it can log the user out
  939. 39:59saying you have to log in again right
  940. 40:01those kinds of actions they can be
  941. 40:03judged with response codes or imagine
  942. 40:06let's say it was a bad request error
  943. 40:08because of some invalid value through a
  944. 40:10form submission then the client can ask
  945. 40:13their user to make changes to their form
  946. 40:16submission and resubmit right depending
  947. 40:18on those status code which was like 400
  948. 40:21also standardization HTTP response codes
  949. 40:24are standardized across all web services
  950. 40:26enabling consistency in how servers
  951. 40:29communicate with different clients
  952. 40:31regardless of the platform or language
  953. 40:34used it does not matter whether you are
  954. 40:36making a server in python or golang or
  955. 40:38rust or JavaScript or Ruby you have to
  956. 40:42follow this standard if the request was
  957. 40:44successful you have to return to 200 if
  958. 40:46the if you created something you have to
  959. 40:48return to1 these are the standards and
  960. 40:50you have to follow them now before HTTP
  961. 40:53status course clients would have to
  962. 40:54guess the outcome of a request based on
  963. 40:56the content of the response as I said
  964. 40:58leading to inconsistencies and
  965. 41:01inefficiencies HTTP status code solve
  966. 41:03this by providing a universal language
  967. 41:05that all clients and servers understand
  968. 41:08streamlining interactions and error
  969. 41:10handling on a high level response codes
  970. 41:12are three-digit numbers they could
  971. 41:14either start with 1 2 3 4 or five and
  972. 41:19depending on the starting digit we
  973. 41:21categorize them as different level of
  974. 41:24errors or different types of errors on a
  975. 41:26high level
  976. 41:27the digits starting with one are
  977. 41:30informational responses two are success
  978. 41:33responses three are redirection five are
  979. 41:35server errors four are client errors
  980. 41:37response codes starting with one this
  981. 41:40code is sent by the server to indicate
  982. 41:42that it has received the headers and the
  983. 41:44client can proceed to send the request
  984. 41:46body and when is it used commonly used
  985. 41:49in large uploads the client sends the
  986. 41:51headers first and if the server is okay
  987. 41:54with the request it sends a 100 Contin
  988. 41:56so the client can send and the rest of
  989. 41:58the body also there is which is which is
  990. 42:01used for switching protocols right we
  991. 42:03have a use case for that this indicates
  992. 42:05that the server is switching protocols
  993. 42:07as requested by the client such as
  994. 42:09upgrading from HTTP to websocket this is
  995. 42:12not the mostly used response codes that
  996. 42:15you will encounter on your day-to-day
  997. 42:16life so let's focus on these four which
  998. 42:19you'll see a lot of times especially 2 4
  999. 42:22and 5 200 series as you know are used
  1000. 42:26for success responses and under that we
  1001. 42:29have three mostly used ones one is
  1002. 42:32200 and
  1003. 42:342011 and 204 200 is the most common code
  1004. 42:38it indicates that the request was
  1005. 42:40successful and the server is returning
  1006. 42:42the requested resource or performing the
  1007. 42:44requested action for example successful
  1008. 42:47get request where a resource is
  1009. 42:48retrieved
  1010. 42:502011 it indicates that the request has
  1011. 42:52been fulfilled and resulted in a
  1012. 42:55creation of a new resource for example
  1013. 42:57post request or new form submissions
  1014. 42:59that's where servers use this response
  1015. 43:02to indicate that the a new resource has
  1016. 43:04been
  1017. 43:06created then we have 204 that we just
  1018. 43:09saw in a course flow when we send
  1019. 43:11options request a pre-flight request and
  1020. 43:14the server responds with 204 saying that
  1021. 43:17there is no content but these are the
  1022. 43:18information in the form of headers this
  1023. 43:20also indicates that the request was
  1024. 43:22successful but there is no content we
  1025. 43:25also sometimes use it for delete delete
  1026. 43:27request right the client makes a delete
  1027. 43:29request you delete the particular
  1028. 43:31resource but the server says okay I've
  1029. 43:33deleted it but there is no content to
  1030. 43:35return right you can just assume that
  1031. 43:37the request was successful then we have
  1032. 43:39300 and in 300 the mostly used ones are
  1033. 43:4331
  1034. 43:45302 and
  1035. 43:47304 301 means moved
  1036. 43:51permanently which means the requested
  1037. 43:54resource has been permanently moved to a
  1038. 43:56new UR URL and the future request should
  1039. 43:59use this new URL for example let's say
  1040. 44:02initially you had a route called
  1041. 44:05user and eventually you decided to move
  1042. 44:09that route to slash person so in order
  1043. 44:12to maintain backwards compatibility so
  1044. 44:14that old users or old applications that
  1045. 44:18are still using this route don't break
  1046. 44:21what you do is you add a 301 response
  1047. 44:24for this routes and read direct then to
  1048. 44:28the/ person route so it is a permanent
  1049. 44:31redirect the next one is 302 which means
  1050. 44:34temporary redirect the requested
  1051. 44:36resource is temporarily located at a
  1052. 44:38different URL but the client should
  1053. 44:40continue to use the original URL for
  1054. 44:42future request so when do we use this
  1055. 44:44let's imagine you are running a campaign
  1056. 44:46or something and for those couple of
  1057. 44:49hours you want to redir redirect a
  1058. 44:52particular route to a new route for
  1059. 44:55catching new traffic or showing a
  1060. 44:57different UI or something like that but
  1061. 44:59you don't want to stick to that right
  1062. 45:02you want to revert the changes so you
  1063. 45:04want to say to the client that for for
  1064. 45:06now I'm making a redirect but later on
  1065. 45:09you should use the original route only
  1066. 45:11and then we have
  1067. 45:1334 which says not modified it indicates
  1068. 45:16that the resource has not been modified
  1069. 45:19since the last time the client requested
  1070. 45:21it and this we will see soon in a bit in
  1071. 45:24a uh when we explore our caching demo
  1072. 45:27and when do we use it this is mostly
  1073. 45:29used in conjunction with conditional get
  1074. 45:31request to allow efficient caching right
  1075. 45:33when we are using e tax to let the
  1076. 45:35client know that the uh response is not
  1077. 45:38modified it should use the cached one
  1078. 45:40only instead of downloading the new
  1079. 45:42response so it just says that it is not
  1080. 45:44modified so you should keep using your
  1081. 45:46old response the cach response then we
  1082. 45:50have the 400 series errors and as a
  1083. 45:52backend engineer I think you will mostly
  1084. 45:55deal with these errors because these are
  1085. 45:58the client errors or errors that are
  1086. 46:00triggered because of something some
  1087. 46:03behavior from client so let's see what
  1088. 46:06are the common ones the first one is
  1089. 46:10400 and what this means is it says bad
  1090. 46:14request and when does it Trigger or when
  1091. 46:17should we fire it for example when the
  1092. 46:19client sends invalid data or illogical
  1093. 46:22data or something related to data right
  1094. 46:25for example you are expecting a number
  1095. 46:27and the client sends an array or a
  1096. 46:30string right you are expecting an email
  1097. 46:32but the client sends a phone number
  1098. 46:34something like that it's a bad request
  1099. 46:37that's what it says and you're letting
  1100. 46:39the client know that there is something
  1101. 46:40wrong with your request format so fix it
  1102. 46:43and make a new request the next one is
  1103. 46:46401 which is which means unauthorized
  1104. 46:49when should you fire this when a request
  1105. 46:51requires authentication but the client
  1106. 46:53has either failed to provide valid
  1107. 46:55credentials or is not authenticated at
  1108. 46:58all so let's say you are expecting a JWT
  1109. 47:01token and either if the JWT token has
  1110. 47:05expired or if the client has not send
  1111. 47:07the token in the first place so in those
  1112. 47:09scenarios you want to say that you are
  1113. 47:11unauthorized that's when you respond
  1114. 47:13with this status code 401 next up we
  1115. 47:16have
  1116. 47:17403 and it says forbidden which means
  1117. 47:21the server understood the request but it
  1118. 47:24refuses to authorize and this can happen
  1119. 47:27even if the client is authenticated for
  1120. 47:29example when a user tries to access a
  1121. 47:31resource they don't have permission to
  1122. 47:33access so let's say you are user a and
  1123. 47:35you are trying to delete a resource of
  1124. 47:37user B so that's when the server says
  1125. 47:40you don't have the necessary permissions
  1126. 47:42to perform this action so you are
  1127. 47:44forbidden 403 next up we have 404 and it
  1128. 47:48means not found I think this is the most
  1129. 47:50famous status code 404 this is fired
  1130. 47:53when the client requests a resource that
  1131. 47:55is unavailable
  1132. 47:57either because the URL is incorrect or
  1133. 47:59the resource has been deleted so in
  1134. 48:02those cases the service is 404 it is not
  1135. 48:04found then we have 405 which means
  1136. 48:07method not allowed when does it get
  1137. 48:10fired when an invalid HTTP method is use
  1138. 48:13such as trying to put to a resource that
  1139. 48:16only accepts get or post this often
  1140. 48:18happens because of typos right we are
  1141. 48:21working on front end and instead of
  1142. 48:23doing a put request we do a patch
  1143. 48:25request or instead of doing a post
  1144. 48:27request we do a put request so in those
  1145. 48:29scenarios server says 405 which means
  1146. 48:31method not allowed then we have
  1147. 48:34409 which means conflict this has a
  1148. 48:38number of use cases one of which we can
  1149. 48:41imagine is let's say in your app you are
  1150. 48:43allowing users to create folders right
  1151. 48:47and the condition is the folder names
  1152. 48:50has to be unique they cannot create two
  1153. 48:52folders with the same name when they try
  1154. 48:54to create a new folder when they submit
  1155. 48:56a post request you check whether the
  1156. 48:58folder is already existing or not if it
  1157. 49:01is you can respond with this error 409
  1158. 49:04conflict so the client will understand
  1159. 49:06that a folder with that name already
  1160. 49:08exists and it should try with a new
  1161. 49:11folder name right it means conflict and
  1162. 49:14at last we have 4 to9 which means too
  1163. 49:18many requests and this is mostly used
  1164. 49:21when we are trying to rate limit uh the
  1165. 49:23client's request rate limit basically
  1166. 49:25means if client tries to make too many
  1167. 49:28requests in a particular interval let's
  1168. 49:31say in your server you have configured
  1169. 49:33it to allow at most 60 requests for a
  1170. 49:38client in 1 second and if the client
  1171. 49:40tries to exceed that you can respond
  1172. 49:43with this response code which ISS 429
  1173. 49:46too many requests okay let's move on to
  1174. 49:49the 500 series and we have the most
  1175. 49:51famous one which is the 500 which means
  1176. 49:55internal server error this is often used
  1177. 49:58for unexpected conditions in server
  1178. 50:00something some process broke or some
  1179. 50:03exceptions were raised which were not
  1180. 50:06handled in the server so something
  1181. 50:08unexpected happened at the server so
  1182. 50:11instead of you know just returning a
  1183. 50:13empty response or just breaking or
  1184. 50:16hanging the request we respond with 500
  1185. 50:19internal server errors the client knows
  1186. 50:21that something went wrong with the
  1187. 50:22server then we have 501 which means not
  1188. 50:25implemented for example example when the
  1189. 50:27server does not support the requested
  1190. 50:29HTTP method or functionality but it
  1191. 50:32plans to edit soon so that's when we add
  1192. 50:35a 501 which means currently it is not
  1193. 50:37supported it might be in the future
  1194. 50:40right so we are trying to get that
  1195. 50:42intention through to the client so that
  1196. 50:45it is not implemented yet then we have
  1197. 50:48502 right it means bad gateway we
  1198. 50:52usually see this in Proxes like NX it
  1199. 50:55means when a server acts as a proxy like
  1200. 50:57in a load balance system or reverse
  1201. 50:59proxy and Upstream server returns an
  1202. 51:01invalid response so that's when 52 is
  1203. 51:05returned this is not something we uh
  1204. 51:08return intentionally this is handled
  1205. 51:09mostly by Proxes and load balancers then
  1206. 51:12we have
  1207. 51:13503s which means service unavailable
  1208. 51:17when the service is down when the
  1209. 51:18service is temporarily unable to handle
  1210. 51:21the request such as during high traffic
  1211. 51:23or when it is going maintenance so
  1212. 51:26that's when you return 503 to let the
  1213. 51:28client know that the service is
  1214. 51:30unavailable right now and it should try
  1215. 51:33again later at last we have
  1216. 51:36504 which means gway time out it is
  1217. 51:40similar to 502 but this specifically
  1218. 51:43means that the Upstream server failed to
  1219. 51:46respond within timeout period let's say
  1220. 51:49you have you're using enginex and
  1221. 51:51enginex could not get a response from
  1222. 51:53our original server which is running
  1223. 51:55behind it so that's when ninx responds
  1224. 51:58with 504 Gateway timeout that it did not
  1225. 52:00receive any response from our original
  1226. 52:02server that's why it says timeout okay
  1227. 52:05that's all that's pretty much all the
  1228. 52:07response codes you need to know to work
  1229. 52:09with
  1230. 52:1095% of use cases now in order to
  1231. 52:13solidify our understanding let's look at
  1232. 52:16a quick demo where we look at some of
  1233. 52:18these responses okay now again we have a
  1234. 52:21friend end app for this demo where we
  1235. 52:24are trying to emulate some of the
  1236. 52:26response resp CES and there is a server
  1237. 52:28running which will respond with
  1238. 52:29different status codes right okay so
  1239. 52:33what we'll do is let's just fire all of
  1240. 52:35these requests then we will examine what
  1241. 52:37the responses look
  1242. 52:39like so let me go
  1243. 52:41ahead
  1244. 52:44and
  1245. 52:45okay
  1246. 52:47created this one one
  1247. 53:01all right we have fired all these
  1248. 53:03requests let's go through one by one so
  1249. 53:05as you can see we have all these options
  1250. 53:08request before each original request
  1251. 53:10because because these are cross original
  1252. 53:12requests the browser need to do
  1253. 53:14pre-flight request to support those
  1254. 53:16let's go through all the original
  1255. 53:17requests one by one to see what are the
  1256. 53:19responses looks like okay the first one
  1257. 53:21was 200 okay as I said this is a
  1258. 53:25successful respon
  1259. 53:27which means request was successful right
  1260. 53:29the status code is 200 and the next one
  1261. 53:33is a post request which says 2011 which
  1262. 53:37means created and This Server response
  1263. 53:40even though it is a mock request and a
  1264. 53:42mock response this is what usually it
  1265. 53:44looks like the resource was created
  1266. 53:45successfully and and the status code is
  1267. 53:472011 then we have 401 bad request says
  1268. 53:53bad request missing required
  1269. 53:55data then we have have then we have 401
  1270. 53:58which means unauthorized which which
  1271. 54:01typically means either you have not
  1272. 54:02included the token the JWT token or the
  1273. 54:06cookie or whatever authentication
  1274. 54:08mechanism you're using whether you are
  1275. 54:10not you have not included that or even
  1276. 54:13if you have it has expired or it is not
  1277. 54:16valid anymore next we have forbidden
  1278. 54:19which means you're trying to perform
  1279. 54:22some action which are not authorized to
  1280. 54:24do right that's why it says 40 through
  1281. 54:26forbidden you do not have access next up
  1282. 54:29we have 404 which means not found and
  1283. 54:32the server says something like not found
  1284. 54:34the requested resource could not be
  1285. 54:36found next we have 409 conflict which is
  1286. 54:41resource already exists so this could
  1287. 54:43happen when as our previous example
  1288. 54:46maybe you already have a folder and
  1289. 54:47you're trying to create a folder with
  1290. 54:49with the same name again so that's why
  1291. 54:51the server says resource already exists
  1292. 54:53right then we have internal server
  1293. 54:58error which is 500 and the server just
  1294. 55:01says internal server error without
  1295. 55:03letting the client know too much of the
  1296. 55:05information for security reasons then we
  1297. 55:08have 503 service unavailable please try
  1298. 55:11again later right that's pretty much
  1299. 55:13covers most of the status Cotes that we
  1300. 55:16have discussed and that we saw in this
  1301. 55:19demo okay moving on let's explore
  1302. 55:22another interesting concept HTTP caching
  1303. 55:24what does http caching mean HTTP caching
  1304. 55:27is a technique to store copies of
  1305. 55:29responses for reuse reducing the need to
  1306. 55:32repeated request to the server this
  1307. 55:33improves load time reduces uh bandwidth
  1308. 55:37and decreases server load right because
  1309. 55:39the client does not need to download a
  1310. 55:41lot of data and the server does not need
  1311. 55:42to send a lot of data if the data is not
  1312. 55:45changed this client can just reuse the
  1313. 55:47old data right that's what caching means
  1314. 55:49reusing the old data if the data is not
  1315. 55:52changed in order to understand this
  1316. 55:54let's just go through a demo instead of
  1317. 55:56of going it theoretically how it looks
  1318. 55:58like practically in a browser
  1319. 56:00environment okay let's go to the request
  1320. 56:03cycle and understand how caching works
  1321. 56:06by following the trail let let me just
  1322. 56:09do a refresh so when we first render the
  1323. 56:12page we are doing a fetch operation so
  1324. 56:14let's start from there okay we fired all
  1325. 56:17these requests and what you want is the
  1326. 56:19last one right because these are just uh
  1327. 56:23JavaScript files and CSS and stuff okay
  1328. 56:26okay what happened in the last request
  1329. 56:30Let's see we did a get request to this
  1330. 56:33endpoint API resource and there is
  1331. 56:36nothing else in the request headers that
  1332. 56:38we should focus on right now right let
  1333. 56:41come let's come to the response what did
  1334. 56:43the server respond with the first
  1335. 56:45important thing is this one cache
  1336. 56:48control what it says is you should
  1337. 56:51maintain the cash for this resource for
  1338. 56:55maximum 10 seconds right this is the
  1339. 56:57first important header the next is e tag
  1340. 57:01e tag is basically a hash so for the
  1341. 57:05sake of this example we are using a
  1342. 57:07random number but eags are usually
  1343. 57:10hashes which are computed from a
  1344. 57:12response for example the server might
  1345. 57:14have taken this response hashed it and
  1346. 57:17sent us that hash in the form of E tag
  1347. 57:20right and we will see what is the use of
  1348. 57:22that in the next request the next
  1349. 57:24important header is last modified with
  1350. 57:27this what the server is trying to say is
  1351. 57:29this is the last time this request was
  1352. 57:31modified and judging from this time and
  1353. 57:34date we can decide whether we should use
  1354. 57:36the old resource the cash resource or
  1355. 57:39request for a new one these are the
  1356. 57:41three important headers that we are
  1357. 57:43going to use for caching okay so that is
  1358. 57:47the initial request and in this request
  1359. 57:49the server responded with a 200 along
  1360. 57:52with the requested resource whatever
  1361. 57:54that is we won't focus on that we are
  1362. 57:56just seeing there is a response body all
  1363. 57:59right what happens when we do a fetch
  1364. 58:02operation for the same resource right
  1365. 58:04let's do a
  1366. 58:09fetch okay what happened here let's look
  1367. 58:12at the response let's focus on the
  1368. 58:15request first we are again doing a get
  1369. 58:18request to this end point and now the
  1370. 58:21headers to focus in the request is this
  1371. 58:24these two headers if none match and if
  1372. 58:28modified since what we are trying to say
  1373. 58:31to the server is if the E tag the hashed
  1374. 58:33version of the response object the E tag
  1375. 58:37of the requested resource is not the
  1376. 58:39same as this one which we have with us
  1377. 58:41in the browser or if the request has
  1378. 58:44been modified after this which means we
  1379. 58:47have the outdated version right we are
  1380. 58:49saying if the eag does not match or if
  1381. 58:53the request has been modified after this
  1382. 58:55then send us a new resource then send us
  1383. 58:58the updated resource otherwise I will
  1384. 59:00just use my cach version which I have
  1385. 59:03with me in the browser cache and to that
  1386. 59:05what server says is it responds with 304
  1387. 59:09not modified and we just talked about
  1388. 59:12different response codes right and 304
  1389. 59:14meant the requested resource has not
  1390. 59:17been modified ever since what the server
  1391. 59:19did was it checked the if none match
  1392. 59:21header which is which is the eag and it
  1393. 59:24also checked the last modified and since
  1394. 59:27the resource matched either the eag or
  1395. 59:30the last modified it send the client a
  1396. 59:34304 response which means the requested
  1397. 59:37resource has not been modified ever
  1398. 59:39since from the last time you fetched it
  1399. 59:41so you can use you can go ahead and use
  1400. 59:45your cast version let's update the
  1401. 59:46resource for now let's clear
  1402. 59:49this and let's fire an update
  1403. 59:54resource okay what what happened here
  1404. 59:57let's explore the first request okay
  1405. 1:00:00ideally we should have done a patch
  1406. 1:00:02request or put request but for the sake
  1407. 1:00:05of this example again we just fired a
  1408. 1:00:08request a post request okay we updated
  1409. 1:00:10the resource and the server responded
  1410. 1:00:12with 200 okay and it also sent us a new
  1411. 1:00:14e tag right 2943 and after that the
  1412. 1:00:19client did a new get request in this as
  1413. 1:00:22you can see the client sent the old dag
  1414. 1:00:25which which was 3141 our cast version so
  1415. 1:00:29client did a get request with the old
  1416. 1:00:32eag and the last modified sense to the
  1417. 1:00:35server and the server responded with 200
  1418. 1:00:37instead of 304 because the resource has
  1419. 1:00:40been modified after that right because
  1420. 1:00:42we did a update resource request and the
  1421. 1:00:46server responded with 2943 which is the
  1422. 1:00:50updated e tag the last modified Etc and
  1423. 1:00:54let's go ahead again do a fet
  1424. 1:00:59request okay and what do we have here we
  1425. 1:01:03are again using the eag that was just
  1426. 1:01:05provided by the server in this request
  1427. 1:01:08right this was 200 and the server
  1428. 1:01:12provided as with a new e tag we are
  1429. 1:01:14using that e tag and the last modified
  1430. 1:01:17value and we are doing another get
  1431. 1:01:19request so the server checked it again
  1432. 1:01:21and since it is the latest version of
  1433. 1:01:23the resource it again responded with 304
  1434. 1:01:25for not modified so this is how you
  1435. 1:01:29handle caching using the HTTP protocol
  1436. 1:01:31using different headers in server and
  1437. 1:01:34client even though in a production
  1438. 1:01:36setting it gets a lot complicated
  1439. 1:01:38because the server has to manually
  1440. 1:01:40Implement and manage all these e tags
  1441. 1:01:43and if by mistake forgot to update an e
  1442. 1:01:45tag right then the client will continue
  1443. 1:01:48to use the cast version with the
  1444. 1:01:50outdated resource which is not a good
  1445. 1:01:52idea nowadays we have better Solutions
  1446. 1:01:55for caching right for example react
  1447. 1:01:58query which is a complete client side
  1448. 1:02:00caching so the client has the complete
  1449. 1:02:03power over when it wants to use a cach
  1450. 1:02:06resource and when it wants to refetch
  1451. 1:02:09right at what interval and all these
  1452. 1:02:12powerful capabilities which is in my
  1453. 1:02:14opinion a much better solution compared
  1454. 1:02:17to the traditional HTTP based caching
  1455. 1:02:20but it is good to know that we have this
  1456. 1:02:23option if our use cases simple enough
  1457. 1:02:26then we can go ahead and use HTTP based
  1458. 1:02:29caching moving on another important
  1459. 1:02:32topic that usually comes up in client
  1460. 1:02:35server model in HTTP is content
  1461. 1:02:38negotiation we already looked at some of
  1462. 1:02:40these headers for example accept the
  1463. 1:02:43content type application gson Etc so
  1464. 1:02:47this is an important topic to understand
  1465. 1:02:49how clients and servers exchange
  1466. 1:02:52information about different types and
  1467. 1:02:55and coding and representation of the
  1468. 1:02:57content this is basically a mechanism
  1469. 1:03:00using which client and server agree on
  1470. 1:03:03the best format to exchange data the
  1471. 1:03:06client can indicate its preferred format
  1472. 1:03:09like Json or XML or HTML and the server
  1473. 1:03:13will try to respond with a compatible
  1474. 1:03:15format or if not available a fallback
  1475. 1:03:18format that is the whole idea to look at
  1476. 1:03:20a high level we have generally three
  1477. 1:03:22types of content negotiation one is a
  1478. 1:03:25med type which means the client
  1479. 1:03:27specifies the desired format through the
  1480. 1:03:29accept header which is application Json
  1481. 1:03:32or XML then we have the language
  1482. 1:03:35negotiation the client requests content
  1483. 1:03:37in a specific language using the accept
  1484. 1:03:40language header uh it could be English
  1485. 1:03:43or Spanish then we have encoding
  1486. 1:03:45negotiation right the client specifies
  1487. 1:03:49which encoding it supports using the
  1488. 1:03:51accept encoding header like gz or
  1489. 1:03:54deflate and the server responds with
  1490. 1:03:58that compression format we have a topic
  1491. 1:04:00which is HTTP compression which is also
  1492. 1:04:03part of this topic only so we will
  1493. 1:04:05quickly see that also in the demo that's
  1494. 1:04:07the whole idea and let's just jump into
  1495. 1:04:09the demo to understand how it works and
  1496. 1:04:11again there is a server running which
  1497. 1:04:13will help us understand different types
  1498. 1:04:15of content negotiation and this is a
  1499. 1:04:17frontend client through which we will
  1500. 1:04:19communicate with our server so let's
  1501. 1:04:21just try out different types of requests
  1502. 1:04:24and we'll see how the headers differ and
  1503. 1:04:26how the responses differ depending on
  1504. 1:04:28the types of headers the client is
  1505. 1:04:29sending okay let's first just try the
  1506. 1:04:32default one which is which is a language
  1507. 1:04:34is English the format is Json and the
  1508. 1:04:38preferred encoding is jip so let's do F
  1509. 1:04:41FD source and this is what the request
  1510. 1:04:43and response looks like okay so it was a
  1511. 1:04:47get request to this
  1512. 1:04:50endpoint and what we said is the
  1513. 1:04:53language we are saying is English we are
  1514. 1:04:56sending that information using the
  1515. 1:04:58accept language header that we prefer
  1516. 1:05:01the English language then what we are
  1517. 1:05:03saying is the format is Json right we
  1518. 1:05:06send that with accept application Json
  1519. 1:05:09and there is the encoding header right
  1520. 1:05:12that we are saying accept encoding the
  1521. 1:05:15browser supports these kinds of
  1522. 1:05:17encodings right JZ defl VR and zsd so we
  1523. 1:05:21said we are expecting English and in
  1524. 1:05:23Json format so this how this is how the
  1525. 1:05:27server responded it it is sending us a
  1526. 1:05:29Json
  1527. 1:05:31and it is in English so let's trve one
  1528. 1:05:34thing let's make it to Spanish and see
  1529. 1:05:37how the response
  1530. 1:05:38differs I made it Spanish and add did
  1531. 1:05:42another
  1532. 1:05:43fetch okay so let's see how this differs
  1533. 1:05:46in this the only thing that changed was
  1534. 1:05:49instead of accept language English in
  1535. 1:05:51the header the client said accepted
  1536. 1:05:53language is Spanish so depending on on
  1537. 1:05:55that the server was able to update the
  1538. 1:05:58response so instead of sending it in
  1539. 1:06:00English since the client prefers Spanish
  1540. 1:06:02the server responded with Spanish and
  1541. 1:06:05what if we change the format from Json
  1542. 1:06:08to XML and we do a
  1543. 1:06:11Fetch and we look at this what change
  1544. 1:06:14here we are saying we accepted format is
  1545. 1:06:17XML and the accepted language is Spanish
  1546. 1:06:21this is the XML format and the language
  1547. 1:06:24is Spanish and on a high level this
  1548. 1:06:27these are the benefits of using content
  1549. 1:06:29negotiation based headers right the
  1550. 1:06:30client can let the server know what are
  1551. 1:06:33its preferences whether it is the data
  1552. 1:06:36format or the language of the data and
  1553. 1:06:39depending on that the server can decide
  1554. 1:06:42to send according to that format it can
  1555. 1:06:45make the life of the client Easier by
  1556. 1:06:47sticking to the preferences those are
  1557. 1:06:49the primarily two type of content
  1558. 1:06:51negotiations while we are discussing
  1559. 1:06:54content negotiation there is one
  1560. 1:06:56interesting topic which falls under the
  1561. 1:06:57same umbrella which is HTTP based
  1562. 1:07:00compression it could be either gzip
  1563. 1:07:01deflate or other formats right so let's
  1564. 1:07:05look at why do we need compression and
  1565. 1:07:08how does it work so now what I've done
  1566. 1:07:10is I've gone ahead and replace the Json
  1567. 1:07:13response with a very large file file of
  1568. 1:07:1511,000 entries now let's file the
  1569. 1:07:22request okay this is the response
  1570. 1:07:25response and the size is 3.8 M since
  1571. 1:07:28it's a very large file and let's look
  1572. 1:07:32how the response looks
  1573. 1:07:35like this is what it looks like because
  1574. 1:07:38we are compressing the file on the
  1575. 1:07:40server side with gzip encoding right
  1576. 1:07:43here it says content encoding is gzip
  1577. 1:07:46because the client says it accepts
  1578. 1:07:49encoding of gzip one of the encoding
  1579. 1:07:52formats now why do we use it to show
  1580. 1:07:55that let me just go and disable
  1581. 1:07:58compression in the server side okay and
  1582. 1:08:01now that I have disabled the compression
  1583. 1:08:02let's fire the same request
  1584. 1:08:09again and as you can see the significant
  1585. 1:08:12increase in the size it's the same file
  1586. 1:08:15right it's the same file with 11,000
  1587. 1:08:17entries and because we are using
  1588. 1:08:19compression the file size was 3.8 MB and
  1589. 1:08:22now that we have disabled it the file
  1590. 1:08:25size becomes 26 M that's a huge increase
  1591. 1:08:29in size and imagine every client having
  1592. 1:08:32to download that file it it it caes a
  1593. 1:08:35lot of based of bandwidth and that is
  1594. 1:08:37why we need compression so that if the
  1595. 1:08:40response size is very large we can
  1596. 1:08:43compress it to a format and on the
  1597. 1:08:46client side the browser can decompress
  1598. 1:08:48it and it will get the same response and
  1599. 1:08:51this is another important topic which we
  1600. 1:08:55won't really work with it's good to know
  1601. 1:08:58that it exists behind the scenes in the
  1602. 1:09:00early days of HTTP specifically HTTP 1.0
  1603. 1:09:04each request response cycle required a
  1604. 1:09:06separate connection to the server now
  1605. 1:09:09this created inefficiencies since
  1606. 1:09:11establishing and closing TCP connections
  1607. 1:09:14is resource intensive and slow to
  1608. 1:09:16address this persistent connections were
  1609. 1:09:19introduced in HTTP 1.1 now with
  1610. 1:09:21persistent connections a single TCP
  1611. 1:09:24connection can be reused for for
  1612. 1:09:25multiple requests and responses avoiding
  1613. 1:09:28the overhead of opening and closing a
  1614. 1:09:30collection for every interaction and for
  1615. 1:09:34achieving that they introduced this
  1616. 1:09:36header called keep alive keep alive is
  1617. 1:09:40the mechanism that enables persistent
  1618. 1:09:42connections it allows the client and
  1619. 1:09:45server to reuse the same connection for
  1620. 1:09:47multiple request responses until one of
  1621. 1:09:50them decides to close it so what are
  1622. 1:09:51some key points to remember here in sttp
  1623. 1:09:541.1 connections are persistent by
  1624. 1:09:57default we won't have to do anything
  1625. 1:09:59explicitly about them meaning they
  1626. 1:10:02remain open for further requests unless
  1627. 1:10:04explicitly closed and multiple SB
  1628. 1:10:07request and responses can be sent over a
  1629. 1:10:09single connection this reduces latency
  1630. 1:10:12and saves resources as fewer connection
  1631. 1:10:14need to be established now the second
  1632. 1:10:16thing is the keep alive header while
  1633. 1:10:19persistent connections are default in
  1634. 1:10:21HTTP 1.1 the connection keep alive
  1635. 1:10:24header is it's still sometimes used to
  1636. 1:10:26explicitly ask the server to keep the
  1637. 1:10:29connection open this header can also
  1638. 1:10:32include option like how long the
  1639. 1:10:33connection should remain open with a
  1640. 1:10:36timeout or how many requests can be sent
  1641. 1:10:38before the connection is closed with the
  1642. 1:10:41max value now the third thing is when
  1643. 1:10:43connection is set to close and when that
  1644. 1:10:46is specified the connection is closed
  1645. 1:10:48after the response is sent this is the
  1646. 1:10:51behavior in HTTP 1.0 by default and it
  1647. 1:10:53can still explicitly enforced in HTTP
  1648. 1:10:561.1 that is some amount of information
  1649. 1:10:59you just have to understand but you
  1650. 1:11:01usually won't be working with them the
  1651. 1:11:03default values work fine one last topic
  1652. 1:11:05that I want to cover is handling large
  1653. 1:11:08request and responses how server takes
  1654. 1:11:12in large request like Files video files
  1655. 1:11:15image files audio files any kind of file
  1656. 1:11:17which are very large compared to our
  1657. 1:11:20typical Json and how client can receive
  1658. 1:11:23large responses in the same way so let's
  1659. 1:11:26just jump into the demo and see how it
  1660. 1:11:29usually works now here we have two
  1661. 1:11:31examples in one we will see how clients
  1662. 1:11:35can send large request to the server and
  1663. 1:11:38in the second one we'll see how servers
  1664. 1:11:40can send large responses to the client
  1665. 1:11:43first one is multiart request multiart
  1666. 1:11:46is usually used for sending large files
  1667. 1:11:48or any kind of files to the server from
  1668. 1:11:51the client and the difference between
  1669. 1:11:53our typical Json request body is in
  1670. 1:11:55multiart request the file the data of
  1671. 1:11:59the file the binary data is transferred
  1672. 1:12:01to the server in Parts in different
  1673. 1:12:04parts that's why it is called multiart
  1674. 1:12:06request so let's see how it looks like I
  1675. 1:12:09have selected a picture and let's click
  1676. 1:12:13on upload
  1677. 1:12:15file now let's look at the response of
  1678. 1:12:18this here is what the request looks like
  1679. 1:12:20it is a post request and we are
  1680. 1:12:23specifying a Content length and our
  1681. 1:12:26content type is multiart form data and
  1682. 1:12:30this is the important part the boundary
  1683. 1:12:33and why we need this is since our binary
  1684. 1:12:37data the binary data of the file is
  1685. 1:12:40transferred in parts we want to specify
  1686. 1:12:43what is going to be the delimit what
  1687. 1:12:46will separate the parts right we need
  1688. 1:12:48some kind of code that will separate the
  1689. 1:12:50parts so we are saying this will be our
  1690. 1:12:53delimiter and if we do a search
  1691. 1:12:59here we have the delimeter at the start
  1692. 1:13:02of the binary data and the next
  1693. 1:13:04occurrence
  1694. 1:13:05is at the end of it when the all the
  1695. 1:13:09binary data ends in the request body
  1696. 1:13:12right that is the use of the boundary
  1697. 1:13:14parameter and that is how we transfer a
  1698. 1:13:17large file to the server and the server
  1699. 1:13:19can read the file responds with the some
  1700. 1:13:22details of the file in order to say that
  1701. 1:13:24the upload was successful the idea is
  1702. 1:13:27whenever we want to transfer large files
  1703. 1:13:29to the server we should use multiart
  1704. 1:13:32requests okay now the second thing is
  1705. 1:13:35receiving large responses from the
  1706. 1:13:37server for this demo I have used a large
  1707. 1:13:41text file in the server side and we want
  1708. 1:13:44to stream the data to the client side in
  1709. 1:13:47chunks that's what we want to do so
  1710. 1:13:50let's start the so let's start the
  1711. 1:13:53request and see how it looks like
  1712. 1:13:55click on stream
  1713. 1:13:57data so as you can see this is the first
  1714. 1:14:03chunk okay so if you go
  1715. 1:14:09here you can see that we are receiving
  1716. 1:14:12chunks continuously from the server in
  1717. 1:14:14different different requests so the
  1718. 1:14:15request is pretty much a normal request
  1719. 1:14:18it is a get request let's look at the
  1720. 1:14:20response what the response looks like
  1721. 1:14:22these are the three important things
  1722. 1:14:24that we have to to consider one is
  1723. 1:14:26content type it is saying that it is not
  1724. 1:14:29a text content right it is a text event
  1725. 1:14:31stream which says it will stream the
  1726. 1:14:34data to the client through different
  1727. 1:14:36events and the second one is the
  1728. 1:14:38connection keep alive it says keep the
  1729. 1:14:40connection alive until all the data is
  1730. 1:14:42sent and if is here we are still
  1731. 1:14:44receiving the chunks and we can keep
  1732. 1:14:47scrolling and scrolling and until the
  1733. 1:14:49file is completely transferred the
  1734. 1:14:51server will keep sending the data in
  1735. 1:14:53chunks and how does it work because of
  1736. 1:14:56these headers the content type text
  1737. 1:14:58event stream and the connection keep
  1738. 1:15:00live right and the client keeps
  1739. 1:15:03appending all the data that it is
  1740. 1:15:05receiving from the server and
  1741. 1:15:06constructing this whole text file and
  1742. 1:15:10that is how we transfer a large file
  1743. 1:15:13from a server to the client using chunk
  1744. 1:15:16transfer or text event stream and the
  1745. 1:15:18last thing before we end this lesson I
  1746. 1:15:21just want to give a brief idea about
  1747. 1:15:23what these terms mean SSL or TLS or
  1748. 1:15:26https even though we don't explicitly
  1749. 1:15:28work with them it's good to know what
  1750. 1:15:30are these SSL was the original protocol
  1751. 1:15:34for securing Communications between
  1752. 1:15:36client like a web browser and server it
  1753. 1:15:39encrypts data so that the sensitive
  1754. 1:15:42information like passwords or credit
  1755. 1:15:44card numbers cannot be intercepted by
  1756. 1:15:46attackers right it was the original
  1757. 1:15:48encryption mechanism between clients and
  1758. 1:15:50server now currently SSL is outdated due
  1759. 1:15:54to some some security vulnerabilities
  1760. 1:15:56and has been replaced by TLS so this is
  1761. 1:16:00the modern version of the encryption
  1762. 1:16:02that client and servers use for data
  1763. 1:16:04transmission TLS is a modern and more
  1764. 1:16:07secure version of SSL it encrypts data
  1765. 1:16:09in transit ensuring that any data sent
  1766. 1:16:12between the client and server is
  1767. 1:16:14protected from interception and
  1768. 1:16:16tampering how it works is TLS uses
  1769. 1:16:19certificates to authenticate the server
  1770. 1:16:21and establish an encrypted connection
  1771. 1:16:23preventing Eve dropping and data bries
  1772. 1:16:26TLS is continuously updated with newer
  1773. 1:16:28versions offering better security the
  1774. 1:16:30current recommended version is TLS 1.
  1775. 1:16:34and what is https then https is
  1776. 1:16:37basically HTTP but more secutive
  1777. 1:16:41features which is which are provided by
  1778. 1:16:44SSL or TLS initially it was SSL and now
  1779. 1:16:48it is TLS the underlying mechanism is
  1780. 1:16:50TLS and https is the one which uses TLS
  1781. 1:16:56how it works is when you visit a website
  1782. 1:16:58using
  1783. 1:16:59https TLS encrypts the communication
  1784. 1:17:02between your browser and the server this
  1785. 1:17:05protects sensitive data like login
  1786. 1:17:07credentials from being intercepted by
  1787. 1:17:09the attackers and that much information
  1788. 1:17:11is more than enough on this topic that's
  1789. 1:17:14all you need to know about TLS and sdps
  1790. 1:17:16to work on application Level great we
  1791. 1:17:20talked about a lot of stuff I hope
  1792. 1:17:22you're able to digest that and I hope
  1793. 1:17:25you rewatch some of the sections so that
  1794. 1:17:28you are able to internalize all of them
  1795. 1:17:30and overally this is all you need to
  1796. 1:17:33know about HTTP at least of course there
  1797. 1:17:37are more stuff to read if you want on
  1798. 1:17:39HTTP or TLS or PCP protocol different
  1799. 1:17:43different components of HTTP but in
  1800. 1:17:45order to work on backend systems if you
  1801. 1:17:48understand this much if you internalize
  1802. 1:17:51this much and you can visualize the
  1803. 1:17:53whole flow of all the the components
  1804. 1:17:55that we talked about today then you're
  1805. 1:17:57good to go you'll be able to understand
  1806. 1:17:59all you need to understand and you'll be
  1807. 1:18:01able to debug most of the stuff now that
  1808. 1:18:03you understand how the system works
  1809. 1:18:06behind the scenes and what are the
  1810. 1:18:07components that come into play in
  1811. 1:18:09different different flows that's all
  1812. 1:18:11about http

About this transcript

This page contains the full transcript of 5. Understanding HTTP for backend engineers, where it all starts by Sriniously, generated from the public captions YouTube serves with the video. The transcript has 12,458 words across 1,812 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.

What you can do with it

Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to translate the transcript into 100+ languages.

Free YouTube transcript tool

YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, translation to 100+ languages, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.